Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started