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 garlic2.txt, then the output is:
Value read from garlic2.txt: 10
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 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!