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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started