Question: Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it line by line.

Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it line by line. While entering the file name, the program should allow the user to type quit to exit the program. If the file with a given name does not exist, then display a message and allow the user to re-enter the file name.

The file can contain one or more sentences. The program should accept as input each sentence in which all the words are run together, but the first character of each word is uppercase. Convert sentences to strings in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string StopAndSmellTheRoses. would be converted to Stop and smell the roses. Sentences are separated by periods ('.'), exclamation marks ('!'), or question marks ('?'). Ensure that there is one space character in between sentences.(I NEED JAVA CODE).

standard input

text1.txt

Required Output

Please enter the file name or type QUIT to exit: Stop and smell the roses. 

standard input

txt1.txt text1.txt 

Required Output

Please enter the file name or type QUIT to exit: File 'txt1.txt' is not found. Please re-enter the file name or type QUIT to exit: Stop and smell the roses. 

Standard Input

text2.txt

Please enter the file name or type QUIT to exit: A true rebel you are! Everyone was impressed. You'll do well to continue in the same spirit. Please explain a bit more in the way of footnotes. From the given text it's not clear what are we reading about. 

standard input

somefile.txt anotherbadfile.txt quit 

Required Output

Please enter the file name or type QUIT to exit: File 'somefile.txt' is not found. Please re-enter the file name or type QUIT to exit: File 'anotherbadfile.txt' is not found. Please re-enter the file name or type QUIT to exit: 

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!