import java.io.*; public class TestBufferedReader { public static void main(String[] args) { String text; try { // Creates a BufferedReader object that takes a // FileReader object as an argument. The FileReader // associates an object with the file to be read. BufferedReader br = new BufferedReader(new FileReader("texttoread.txt")); // The while loop calls the readLine method as long as // there is a line of characters to be read. while ((text = br.readLine()) != null) { System.out.println(text); } // Always close a file after opening. br.close(); } // Catch and handle the exception in the // event that the named file cannot be found. catch (FileNotFoundException fnfe) { System.out.println(fnfe); return; } // Catch and handle an exception if there is // a problem reading the file. catch (IOException ioe) { System.out.println(ioe); } } }