Question
14. This method to print disk files that have String content has a problem: public void printTextFile(String fileName) throws IOException { BufferedReader diskFile = new
14. This method to print disk files that have String content has a problem: public void printTextFile(String fileName) throws IOException { BufferedReader diskFile = new BufferedReader( new FileReader(fileName)); while(true) { System.out.println(diskFile.readLine().trim()); } } If the input file named by the parameter is not found, FileNotFoundException (a child class of IOException) is thrown back to the caller as expected. The programmer also anticipates that EOFException (another child class of IOException) will be thrown when EOF (End-Of-File) is reached. But the method above always blows up with a NullPointerException! Show simple alternate code ***for the while() loop*** that would accomplish file reading, triming, and printing without blowing up. (P.S. Do not throw Exceptions other than IOException back to the caller.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started