How to Write file handling program to copy characters from one file to another in java?.

How to Write file handling program to copy characters from one file to another in java?.

Example: copy characters from one file to another in Java
 

import java.io.*;

class CopyChartest

{

public static void main(String[] args)

{

File infile = new File("my java.txt");

File outfile = new File("hello java.txt");

FileReader fr=null;

FileWriter fw=null;

try{

fr = new FileReader(my java);

fw = new FileWriter(hello java);

int ch;

//FileReader Class which is subclass of InputSteamReader//

fw.write(ch);}

}catch(IOException e){

System.out.println(e);

System.exit(-1);}

finally{

try{

fr.close();

fw.close();

}

catch(IOException e){}

}}}

Read More →