Question: CHALLENGE ACTIVITY 4 . 3 . 1 : Exceptions with files. 5 2 2 5 6 2 . 3 5 7 8 1 9 4

CHALLENGE
ACTIVITY
4.3.1: Exceptions with files.
522562.3578194 qxi3zqy?
Jump to level 1
String avocadoDataName is read from input. The try block opens a file named avocadoDataName to read an integer into dataValue.
Complete the try-with-resources statement to declare a Scanner object named avocadoScanner with a FilelnputStream constructed with string avocadoDataName.
Ex. If the input is avocado2.txt, then the output is:
Value read from avocado2.txt: 29
Ex: If the input is invalid.txt, then the output is:
Error opening file: invalid.txt
avocado2.txt
public class ReadDatafile {
public static void main(String [] args){
Scanner scnr = new Scanner(
System.in);
String avocadoDataName;
int dataValue;
avocadoDataName =scnr*next();
try (/* Your code goes here *{
dataValue = avocadoScanner . nextInt ();
}
System.out.println("Value read from "+ avocadoDataName +": "+ dataValue);
catch (IOException e){
}
System.out.println("Error opening file: "+ avocadoDataName);
 CHALLENGE ACTIVITY 4.3.1: Exceptions with files. 522562.3578194 qxi3zqy? Jump to level

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!