• Post Reply Bookmark Topic Watch Topic
  • New Topic

Search word in text file  RSS feed

 
sri syamimie ibrahim
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...i need a java code to search a certain word from the text file. the word that i want to search is in other text file. and finally the output will print the result in the new text file. for the example the text file name data.txt and the word list in the wordlist.txt and the output will print filter.txt. i hope anyone can help me to solve my problem. tq
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to The Ranch!

We love to help but won't do your work for you. You wouldn't learn anything if we just handed out solutions. (read the link -> NotACodeMill)

Show us what you have done so far. What particular part are you currently stuck on? (read the link -> ShowSomeEffort)
 
sri syamimie ibrahim
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what i need to do to print the output in the file .txt??

 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have added code tags which you should always use, and don't they make your post look better

You should use the standard techniques for writing to text files. Start in the Java Tutorials. I might start with a Formatter, for a text file.
Why do you have linecount and tokencount variables? You are not actually using them, so you can delete them. Also they should be lineCount and tokenCount. You know there are readers which count the lines automatically?
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And using FileReader inside a class called Filereader is a good recipe for confusion.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!