// LineCount Example // Check the line count of a file, whose // filename is entered as a command line // argument. Display a user friendly // message if the file is not found. import java.util.Scanner; import java.io.FileReader; import java.io.FileNotFoundException; public class LineCount { public static void main(String[ ] args) { int count = 0; String fileName = args[0]; Scanner s; try { s = new Scanner(new FileReader(fileName)); } catch(FileNotFoundException e) { System.out.println( "File " + fileName + " not found."); System.exit(0); } for(int count = 0; s.hasNext( ); count++) { String line = s.next( ); } System.out.println("Line count = " + count); } }