I think the problem is in the blanks but I don't know what else to try.
package com.codegym.task.task19.task1907;
import java.io.*;
import java.util.Arrays;
/*
Counting words
*/
public class Solution
{
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
FileReader fileReader = new FileReader(reader.readLine());
reader.close();
char[] array = new char[500];
int cont = 0;
while(fileReader.ready())
{
fileReader.read(array);
}
String text = Arrays.toString(array);
text = text.replaceAll("\\s", "");
String[] arrayString = text.split("\\p{Punct}");
for(String s : arrayString)
{
if(s.equals("world"))
{
cont++;
}
}
fileReader.close();
System.out.println(cont);
}
}