Question: String volumeDataFile is read from input. The try block opens a file named volumeDataFile to read a floating - point number into valueRead. Write an
String volumeDataFile is read from input. The try block opens a file named volumeDataFile to read a floatingpoint number into valueRead.
Write an exception handler to catch a FileNotFoundException. In the catch block, output volumeDataFile, followed by : Error occurred". End with a newline.
After the catch block, close fileScanner if fileScanner is open.
Click here for examples
Ex : If the input is volumetxt then the output is:
Value read from volumetxt:
Ex : If the input is nothing.txt then the output is:
nothing.txt: Error occurred
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 volumeFStream;
Scanner fileScanner null;
String volumeDataFile;
double valueRead;
volumeDataFile scnrnext;
try
volumeFStream new FileInputStreamvolumeDataFile;
fileScanner new ScannervolumeFStream;
valueRead fileScanner.nextDouble;
System.out.printlnValue read from volumeDataFile : valueRead;
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
