Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This method to print disk files that have String content has a problem: public void printTextFile(String fileName) throws IOException { BufferedReader diskFile = new BufferedReader(

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

2. Define communication.

Answered: 1 week ago