What is the best way to find the total number of words in a text file in Java? I\'m thinking Perl is the best on finding things such as this. If this is true then calling a
making some assumptions about what defines a 'word', one solution would be to open the file using a text stream reader and scan it, counting the number of non-contiguous whitespace characters, plus one for the end, e.g.
this is some sample text
this is some more sample text
the text above would have 11 words in it, counted as 9 spaces and 1 newline and 1 end-of-file