Java Program – to count the number of words present in a text file.

First create a text file with any name you like In this example inputInfo.txt is the file name. Then insert some sentences in that txt file. The following java code will count the number of words present in that file.

Output: