Question: String onionDataName is read from input. Write a try block to: Assign onionFStream with a new FilelnputStream that opens the file named onionDataName for reading.

String onionDataName is read from input. Write a try block to:
Assign onionFStream with a new FilelnputStream that opens the file named onionDataName for reading.
Assign dataScanner with a Scanner created using onionFStream.
Read the next integer from the file into onionValue.
Ex: If the input is onion 3.txt, then the output is:
Value read from onion3.txt: 33
Ex: If the input is fail. txt, then the output is:
fail.txt: Open operation failed
\table[[onion2.txt,onion3.txt]]
import java.util.Scanner;
import java.io.FileNotFoundException;
import java.io.FileInputStream;
public class ReadInputFile {
public static void main(String [] args){
Scanner scnr = new Scanner(
System.in);
FileInputStream onionFStream;
Scanner dataScanner = null;
String onionDataName;
int onionValue =-1;
boolean errorFound = false;
onionDataName =scnr*next();
1
2
3
4
 String onionDataName is read from input. Write a try block to:

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!