String cashewFileName is read from input. The try block opens a file named cashewFileName to read an integer into dataVal 1. Write an exception handler to catch a FileNotFoundException and assign hasErr with true. 2. After the catch block, close cashewScanner if cashewScanner is open. Ex: If the input is cashew2.txt, then the output is: Value read from cashew2.txt: 21 Ex: If the input is nothing.txt, then the output is: nothing.txt: File not found 1 import java.util.Scanner; 2 import java.io.FileNotFoundException; 3 // This program uses an overloaded FileInputStream Library to check for file closure 4 5 public class ReadInputFile { 6 7 8 9 10 11 12 13 14 15 4005 16 17 ReadinputFile.java public static void main(String[] args) { Scanner scnr = new Scanner(System.in); FileInputStream cashewInStream; Scanner cashewScanner = null; String cashewFileName; int dataValue = -1; boolean hasErr = false; cashewFileName try { cashew1.txt cashew2.txt cashew3.txt = scnr.next(); cashewInStream = new FileInputStream(cashewFileName);
String cashewFileName is read from input. The try block opens a file named cashewFileName to read an integer into dataVal 1. Write an exception handler to catch a FileNotFoundException and assign hasErr with true. 2. After the catch block, close cashewScanner if cashewScanner is open. Ex: If the input is cashew2.txt, then the output is: Value read from cashew2.txt: 21 Ex: If the input is nothing.txt, then the output is: nothing.txt: File not found 1 import java.util.Scanner; 2 import java.io.FileNotFoundException; 3 // This program uses an overloaded FileInputStream Library to check for file closure 4 5 public class ReadInputFile { 6 7 8 9 10 11 12 13 14 15 4005 16 17 ReadinputFile.java public static void main(String[] args) { Scanner scnr = new Scanner(System.in); FileInputStream cashewInStream; Scanner cashewScanner = null; String cashewFileName; int dataValue = -1; boolean hasErr = false; cashewFileName try { cashew1.txt cashew2.txt cashew3.txt = scnr.next(); cashewInStream = new FileInputStream(cashewFileName);
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
ONLY ReadInputFile.java file can be edited with New JAVA CODE
ONLY new code can be added between 21 and 23 (as seen in image).
cashew1.txt
47
cashew2.txt
21
cashew3.txt
25
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 4 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education