Number of Occurrences of a word in a text file or group of text files
While the functional approach may not always be the best solution, I find using Streams on files very convenient. 

If you need to extend the second requirement on directories even further to include all .txt files in subdirectories, you can easily recurse through and flatmap all of the subdirectories until you are left with just a single stream of .txt files.

Code:

public static void main(String[] args) throws IOException {

    Scanner inputReader = new Scanner(System.in);

    System.out.println("Enter a path");
    String inputPath = inputReader.nextLine();
    System.out.println("Enter the word");
    String targetWord = inputReader.nextLine();

    File file = new File(inputPath);

    long numOccurances = 0;

    if(file.isFile() &amp;&amp; file.getName().endsWith(".txt")){

        numOccurances = toLineStreamFromFile(file)
                            .flatMap(str -&gt; Arrays.stream(str.split("\\s")))
                            .filter(str -&gt; str.equals(targetWord))
                            .count();

    }else if(file.isDirectory()){

        numOccurances = Arrays.stream(file.listFiles(pathname -&gt; pathname.toString().endsWith(".txt")))
                              .flatMap(Main::toLineStreamFromFile)
                              .flatMap(str -&gt; Arrays.stream(str.split("\\s")))
                              .filter(str -&gt; str.equals(targetWord))
                              .count();
    }

    System.out.println(numOccurances);
}

public static Stream&lt;String&gt; toLineStreamFromFile(File file){
    try {
        return Files.lines(file.toPath());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return Stream.empty();
}