20)Using FileReader and FileWriter, write a program to perform file copying and any other suitable operations.

PHOTO EMBED

Mon Jul 08 2024 06:16:19 GMT+0000 (Coordinated Universal Time)

Saved by @varuntej #java

import java.io.*;

public class FileCopyExample {

    public static void main(String[] args) {
        try {
            FileReader fr1 = new FileReader("source.txt");
            FileWriter fw2 = new FileWriter("destination.txt");

            int i;
            while ((i = fr1.read()) != -1) {
                fw2.write((char) i);
            }

            System.out.println("File copied");

            fr1.close();
            fw2.close();
        } catch (IOException e) {
            System.out.println("Error: " + e.getMessage());
        }
    }
}
content_copyCOPY