Skip to content

Instantly share code, notes, and snippets.

@geekboots-team
Created March 21, 2024 16:35
Show Gist options
  • Select an option

  • Save geekboots-team/aec4b62209b699aecc17125b05e5e0b1 to your computer and use it in GitHub Desktop.

Select an option

Save geekboots-team/aec4b62209b699aecc17125b05e5e0b1 to your computer and use it in GitHub Desktop.
Java programming example for coping character stream file from directory
/* 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!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment