• Post Reply Bookmark Topic Watch Topic
  • New Topic

Removes all the occurrences of a specified string rom a text file  RSS feed

 
gabriel terry
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/*(Remove text) Write a program that removes all the occurrences of a specified
string from a text file. For example, invoking
java Exercise14_11 John filename
removes the string John from the specified file. Your program should get the
arguments from the command line.*/


I have a problem.
Text document is Match.txt
Match.txt contains a string: "Open the door John"
I tried to create a new file named doc.txt where to put the text from the Match.txt without John word




Error :NoSuchElementException
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should call "output.next()" once for each call to "output.hasNextLine()" - currently the code calls it up to 3 times. Or rather, you should guard each call to "output.next" with a call to "output.hasNext()".
 
gabriel terry
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already try to use before I posted

But in the doc.txt appears just the last word from first Match.txt
Thanks for the answer!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!