import java.io.*; public class CopyTextFile { 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 { String input; BufferedReader in = new BufferedReader(new FileReader(readFile)); PrintWriter out = new PrintWriter(writeFile); while( (input = in.readLine()) != null ) { out.println(input); } out.close(); in.close(); } catch( IOException ex ) { ex.printStackTrace(); } } }