Question: in Collapse.java, write a method called collapseSpaces that accepts two parameters: (1) an input file Scanner and (2) an output file PrintStream. The method should

in Collapse.java, write a method called collapseSpaces that accepts two parameters: (1) an input file Scanner and (2) an output file PrintStream. The method should read the contents of the file and output it with all its tokens separated by single spaces, collapsing any sequences of multiple spaces into single spaces. For example, consider the following text:

 many spaces on this line!

If this text were a line in the file, the same line should be output as follows:

many spaces on this line!

Your main method should prompt the user for input and output filenames, then pass the appropriate Scanner and PrintStream to collapseSpaces method. If the output file already exists, print a message and end program without calling the collapseSpaces method.

Hints:

Your input and output files should be different files (filenames) to avoid overwriting files

Your method should work with input files that have multiple lines. Use a line-based approach. Keep the line breaks the same.

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!