• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

counting no. of occurances of a word in text file using java IO

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want the code for printing the number of occurances of a particular word in text file. for example there is file called one.txt and it has many words, say i just want to print how many times the word london has occured in the file. also i want to replace london with new york say. how do i do this?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We are NotACodeMill - you won't get full working programs here. We are willing to help you out though.

Do you already know how to read text from a file? If so, do you know how to separate that text into words?
 
Mohan Mehra
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added code tags to your code to make it easier to read. Your code depends on the method sop(), which you don't show. I'm assuming it's shorthand System.out.println(). That, and the misspelled, mis-cased "Fileread" means your code won't even compile. If it did, it would just print out the file's characters one by one. I would use the Character.isWhitespace() to identify word divisions. Try fixing the compile errors, and adding something with the whitespace check and see how far that gets you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic