The program below is supposed to open a file whose full pathname is provided by the user in a keyboard entry. Then it is supposed to count the number of words in the file, where any kind of white space is a word delimiter. The program is complete except for a code fragment of several lines in the try block. Provide the missing code fragment. Use an anonymous File object as the Scanner argument when you instantiate the fileIn object. Of course, you can use the same Scanner-class hasNext and next methods for the fileIn object that you used before with the stdIn object when reading from the keyboard.
/************************************************************** WordsInFile.java* Dean & Dean** This counts the words in a text file.*************************************************************/import java.io.*;import java.util.*;public class WordsInFile{public static void main(String[] args){Scanner stdIn = new Scanner(System.in);Scanner fileIn;int numWords = 0;try{<fragment>} // end trycatch (FileNotFoundException e){System.out.println("Invalid filename.");}catch (Exception e){System.out.println("Error reading from the file.");}} // end main} // end WordsInFile classIf the file is the family.txt file displayed in the following exercise, you should get something like this:
Sample session:
Enter full pathname of file:e:/myJava/problems/chapter15/family.txtNumber of words = 63
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.