import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.io.IOException; public class Copy { public static void main(String[] args) { if (args.length != 2) { System.out.println("Usage: java Copy <sourceFilePath> <destinationFilePath>"); return; } try ( FileInputStream fis = new FileInputStream(args[0]); FileOutputStream fos = new FileOutputStream(args[1]) ) { byte[] contents = new byte[fis.available()]; fis.read(contents); fos.write(contents); System.out.println("Contents Copied"); } catch (FileNotFoundException e) { System.out.println("File not found: " + e.getMessage()); } catch (IOException e) { System.out.println("Error reading or writing the file: " + 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