Question: String papayaDataName is read from input. The try block opens a file named papayaDataName to read an integer into papayaData. Write an exception handler to
String papayaDataName is read from input. The try block opens a file named papayaDataName to read an integer into papayaData.
Write an exception handler to catch a FileNotFoundException. In the catch block, output papayaDataName, followed by : File not found". End with a newline.
After the catch block, close fInScanner if fInScanner is open. import java.util.Scanner;
import java.ioFileNotFoundException;
This program uses an overloaded FileInputStream library to check for file closure
public class ReadInputFile
public static void mainString args
Scanner scnr new ScannerSystemin;
FileInputStream papayaDataStream;
Scanner fInScanner null;
String papayaDataName;
int papayaData;
papayaDataName scnrnext;
try
papayaDataStream new FileInputStreampapayaDataName;
fInScanner new ScannerpapayaDataStream;
papayaData fInScanner.nextInt;
System.out.printlnValue read from papayaDataName : papayaData;
Your code goes here
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
