// File: FileIO1.java // // Author: Rahul Simha // Created: Aug 18, 1998 // // Illustrates reading from a file. // A file is read line-by-line and each line is // printed to the screen. import java.io.*; public class FileIO1 { public static void main (String[] argv) { try { // These are the key steps in setting up the read operation. FileReader fr = new FileReader ("testdata"); LineNumberReader lr = new LineNumberReader (fr); // Now read the input lines boolean over = false; int i = 1; do { // Get a line from the file. String inputLine = lr.readLine (); if (inputLine != null) { System.out.println ("Line " + i + ": " + inputLine); i++; } else over = true; } while (! over); // Done. lr.close(); } catch (IOException e) { // If there was a problem... System.out.println (e); } } }