Tested on a real file, works correctly, but keeps failing "The program must output to the console the number of times the word "world" appears in the file."
package com.codegym.task.task19.task1907;

/*
Counting words

*/

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Solution {
    public static void main(String[] args) throws IOException {
        String fileName;
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            fileName = reader.readLine();
        }

        int count = 0;
        try (Scanner scanner = new Scanner(new FileReader(fileName))) {
            while (scanner.hasNext()) {
                String[] words = scanner.nextLine().split("[.]");
                for (String s : words) {
                    if (s.equals("world")) {
                        count++;
                    }
                }
            }
        }

        System.out.println(count);
    }
}