Здравствуйте, я уже понял как решить задачу другим способом, но подскажите, пожалуйста, почему такое решение не верно?
package com.javarush.task.task18.task1823;
import java.io.*;
import java.util.*;
/*
Нити и байты
*/
public class Solution {
public static Map<String, Integer> resultMap = new HashMap<String, Integer>();
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (reader.ready()) {
String fileName = reader.readLine();
if (fileName.equals("exit")) {
reader.close();
return;
}
ReadThread readThread = new ReadThread(fileName);
readThread.run();
}
reader.close();
}
public static class ReadThread extends Thread {
private String fileName;
public ReadThread(String fileName) {
this.fileName = fileName;
}
@Override
public synchronized void run() {
try {
FileInputStream inputStreamReader = new FileInputStream(fileName);
ArrayList<Byte> lists = new ArrayList<>();
int count = 0;
byte[] temp = new byte[1000];
while (inputStreamReader.read() != -1) {
count = inputStreamReader.read(temp);
}
for (int i = 0; i < count; i++) {
lists.add(temp[i]);
}
int max = 0;
int result = 0;
for (byte list : lists) {
if (max < Collections.frequency(lists, list)) {
max = Collections.frequency(lists, list);
result = list;
}
}
resultMap.put(fileName, result);
inputStreamReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}