counting no. of occurances of a word in text file using java IO
posted 5 years ago
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?
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.
Hug your destiny! And hug this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads