Question: Fix the errors and rewrite the following code snippet. The code is written to read a text file containing a single integer value per line

Fix the errors and rewrite the following code snippet. The code is written to read a text file containing a single integer value per line and output that integer. You need to know how to handle Exceptions when reading a file. If you notice this code doesn't handle Exceptions. You are NOT allowed to throw the exception out of this method, you must handle it inside the method itself.
public static void fileRead(String fname){
File f= new File(fname);
Scanner inf = new Scanner(File);
while(inf.next()){
int x= inf.nextLine () ;
}
System.out.println(x);
f. close();
}
 Fix the errors and rewrite the following code snippet. The code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!