Answered step by step
Verified Expert Solution
Link Copied!

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.io.FileNotFoundException;
// This program uses an overloaded FileInputStream library to check for file closure
public class ReadInputFile {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
FileInputStream papayaDataStream;
Scanner fInScanner = null;
String papayaDataName;
int papayaData;
papayaDataName = scnr.next();
try {
papayaDataStream = new FileInputStream(papayaDataName);
fInScanner = new Scanner(papayaDataStream);
papayaData = fInScanner.nextInt();
System.out.println("Value read from "+ papayaDataName +": "+ papayaData);
}
/* Your code goes here */
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

Students also viewed these Databases questions

Question

Define and measure service productivity.

Answered: 1 week ago