import java.io.*; public class CopyBinFile { public static void main(String [] args) { if (args.length < 2) { System.err.println("Insufficient number of arguments!"); return; } File readFile = new File(args[0]); File writeFile = new File(args[1]); if( !readFile.isFile() ) { System.err.println("Input file does not exist or is not a regular file!"); return; } if( !readFile.canRead() ) { System.err.println("Input file is not readable!"); return; } if( writeFile.exists() ) { System.err.println("Output file exists! Unable to overwrite."); return; } try { byte []buffer = new byte[2048]; FileInputStream in = new FileInputStream(readFile); FileOutputStream out = new FileOutputStream(writeFile); int read_len; while( (read_len = in.read(buffer)) != -1 ) { out.write(buffer, 0, read_len); } out.close(); in.close(); } catch( IOException ex ) { ex.printStackTrace(); } } }