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()); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter