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
int count = 0; Scanner sc = new Scanner(new File("my-text-file.txt")); while (sc.hasNext()) { ++count; sc.next(); }