Instructor: Todd Dole
This assignment gives practice writing data to a text file.
Copy your program from Homework 19 and save it as a new class called SaveText (file SaveText.java).
In addition to the previous prompts, ask the user for a file to save the output to.
Then, instead of printing the lines to the screen, open the file that the user specified and write the lines to the file.
Count the number of lines found/written, and display a success message including the number of lines written to the file.
Your code should catch errors with both reading and writing the file, and handle them correctly.
Example Input/Output:
Please enter a file to search: kjv.txt Please enter the text to search for: Ichabod Please enter the name of the file to save the results to: ichabod.txt File ichabod.txt created with 2 lines.
This should result in a file called ichabod.txt containing:
1 Samuel 4:21 And she named the child Ichabod, saying, The glory is departed from Israel: because the ark of God was taken, and because of her father in law and her husband. 1 Samuel 14:3 And Ahiah, the son of Ahitub, Ichabod’s brother, the son of Phinehas, the son of Eli, the LORD’S priest in Shiloh, wearing an ephod. And the people knew not that Jonathan was gone.
Submit your working .java code via Canvas.