Question: In Java 1. Your program should read in from the user the name of the file containing the program to change (prompt with Enter filename:

In Java

1. Your program should read in from the user the name of the file containing the program to change (prompt with "Enter filename: "). If the file cannot be opened, print an error message ("Bad filename") and repeat the prompt to enter the file name. Continue prompting for a filename until they enter a file that your program can successfully open.

2. Your program can assume that the input file is correctly formatted with the next-line brace style.

3. The modified file should be written back to the same file that you read from. You cannot have the file open for reading at the same time that it is open for writing. So you should store the lines that you want to write to the file in an ArrayList of Strings, and then write them to the file after you've closed the Scanner object that you used to read the file.

4. Use a Scanner object to read in from the input file, and a PrintWriter object when writing to the file.

Scanner class documentation

PrintWriter class documentation

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!