Java Programming

Copy Char File

Java programming example for coping character stream file from directory

10/12/2021
0 views
copy-char-file.javaJava
/* Character stream */
import java.io.*;

class copycharfile {
	public static void main(String args[]) throws IOException {
		FileReader freader;
		FileWriter fwrite;
		try {
			freader = new FileReader("charfile.txt");
			fwrite = new FileWriter("outfile.txt");
			int rf;

			/* Reading and writing character till the end */
			while((rf = freader.read()) != -1)
				fwrite.write(rf);
			fwrite.close();
			freader.close();
			System.out.println("File copied successfully!");
		}
		catch(FileNotFoundException e) {
			System.out.println("File not found!");
		}
	}
}





/* Output */
File Not found!

/* ---------------------- */


File copied successfully!
Java tutorialcopy Character FileCoping Files

Related Examples