logo CodeStepByStep logo

removeDuplicatesFromFile

Language/Type: Java Scanner file input
Related Links:

Write a method named removeDuplicatesFromFile that accepts a string representing a file name as its parameter, and opens that file, reading each word in it and printing that word with its duplicate letters removed. For example, if the file myinput.txt contains the following text:

tresssssidder union
iisss hiiirriingg a
neeew bookkeeper !!!!

tteehhh  eeend. 

Then the call of removeDuplicatesFromFile("myinput.txt"); should print the following console output:

tresider union 
is hiring a 

new bokeper ! 

teh end.

Notice that the duplicate characters have been removed from each word in the file, retaining the given line breaks that were present in the file originally. You may assume that the given file exists and is readable. You may also assume that each word on each line of the file is separated by a single space.

Note: You may want to go solve the string problem removeDuplicates first and then paste its solution here so that you can call it as a helper to solve this problem. You can submit both methods in your solution, one after the other.

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.