/** * ReadLines.java * @author Jeff Ondich, 29 October 2010 * * A demonstration of the use of a Scanner to read an input * file one line at a time. */ import java.io.*; import java.util.*; public class ReadLines { public static void main(String args[]) { if (args.length != 1) { System.err.println("Usage: java ReadLines fileName"); System.exit(1); } Scanner fileScanner = null; try { fileScanner = new Scanner(new File(args[0])); } catch (Exception e) { System.err.println(e.toString()); System.exit(1); } while (fileScanner.hasNextLine()) { System.out.println(fileScanner.nextLine()); } } }