Question: Dear students, Please write a Java program that edits a text file to display each complete sentence with a period at the end on a
Dear students,
Please write a Java program that edits a text file to display each complete sentence with a period at the end on a separate line.
Requirements:
Ask the user to input the name of the file containing sentences separated by a period Sentences may be in a single line as a paragraph containing multiple sentences.
Create a temporary file, copy the content from the source file to the temporary file, and perform the required operation write all sentences on different lines without a period
Copy the contents of the temporary file back into the source file.
Use a method or methods in the File class to remove the temporary file.
Ensure the temporary file has a name that is different from all existing files to avoid affecting existing files except for the file being edited
Your program should ask the user for the name of the file to be edited but should generate the name of the temporary file within the program. One possible way to generate the temporary file name is to start with an unlikely name, such as "Temp and append a digit until a name is found that does not name an existing file.
Instructions:
Create a Java program that implements the described functionality.
Use BufferedReader and BufferedWriter for file reading and writing operations.
Use the File class for managing files and directories.
Ensure your program handles exceptions gracefully using trycatch blocks.
Test your program with different input files to verify its correctness.
Sample output:
Let's say we have an input file input.txt with the following content:
This is a sample text file. It contains multiple sentences. Each sentence ends with a period. The sentences are separated by periods.
After running the program, the contents of input.txt will be modified to:
This is a sample text file
It contains multiple sentences
Each sentence ends with a period
The sentences are separated by periods
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
