import java.io.*; /** * This class illustrates how to read in from a file using a * BufferedReader. BufferedReaders are used to efficiently read * from a large file. * * @author alchambers * @version sp18 */ public class MoreFileIO{ /** * Uses a BufferedReader and a FileReader to read in from a file. * Prints the contents of the file to the console. * * @param filename The name of the file to be read */ private static void readWithBufferedReader(String filename){ try{ System.out.println("Here are the contents of the file:"); FileReader file = new FileReader(filename); BufferedReader in = new BufferedReader(file); String line = in.readLine(); // The readLine() method returns null if there is nothing to read while(line != null){ System.out.println(line); line = in.readLine(); } in.close(); } catch(IOException e){ e.printStackTrace(); } System.out.println("We recovered from the exception"); System.out.println("The program is still running!"); } public static void main(String[] args){ //readWithBufferedReader("BlowinWind.txt"); readWithBufferedReader("non existent file"); } }