import java.io.*; class Four { public static void main(String[] args) { String inputFile = args[0]; // first word on the command line String outputFile = args[1]; // next one on the command line int count = Four.countLines(inputFile); Four.reportIntoFile(outputFile, count, inputFile); } public static void reportIntoFile(String name, int lines, String source) { try { FileOutputStream stream = new FileOutputStream(name); PrintWriter out = new PrintWriter(stream, true); out.println("There are " + lines + " lines in file " + source); stream.close(); } catch (Exception e) { System.out.println("Sorry, something went wrong."); } } public static int countLines(String name) { int count = 0; try { FileInputStream cable = new FileInputStream( name ); InputStreamReader receiver = new InputStreamReader(cable); BufferedReader handset = new BufferedReader(receiver); String line = handset.readLine(); while (line != null) { count = count + 1; // System.out.println("(" + line + ")"); line = handset.readLine(); } cable.close(); } catch (Exception e) { System.out.println("Something went wrong: " + e.toString()); } return count; } }