Question: java String garlicFileName is read from input. The try block opens a file named garlicFileName to read an integer into garlicValue. Write an exception handler
java String garlicFileName is read from input. The try block opens a file named garlicFileName to read an integer into garlicValue.
Write an exception handler to catch a FileNotFoundException. In the catch block, output garlicFileName, followed by : Error occurred". End with a newline.
After the catch block, close fScanner if fScanner is open.
Ex: If the input is garlictxt then the output is:
Value read from garlictxt:
Ex: If the input is nothing.txt then the output is:
nothing.txt: Error occurred
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
