что может не найти такой код, проверил, все слова находит
package com.javarush.task.task19.task1907;
/*
Считаем слово
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
FileReader reader1 = new FileReader(reader.readLine());
reader.close();
ArrayList<String> arrayList = new ArrayList<>();
String s = "";
while (reader1.ready()) {
char ch = (char) reader1.read();
s += ch;
}
int k = 0;
String[] strings = s.split(" ");
for (int j = 0; j<strings.length; j++) {
arrayList.add(strings[j]);
}
for (int h = 0; h<arrayList.size(); h++) {
String[] strings1 = arrayList.get(h).split("\n");
if (strings1.length>1) {
arrayList.remove(h);
h--;
for (int l = 0; l<strings1.length; l++) {
arrayList.add(strings1[l]);
}
}
}
for (int i = 0; i<arrayList.size(); i++) {
if (arrayList.get(i).matches("world")) {
k++;
}
}
System.out.println(k);
reader1.close();
}
}