Где ошибка?
package com.javarush.task.task18.task1823;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
/*
Нити и байты
*/
public class Solution {
public static Map<String, Integer> resultMap = new HashMap<String, Integer>();
public static void main(String[] args) throws IOException {
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String fileName = console.readLine();
if (fileName.equals("exit")) {
break;
}
new ReadThread(fileName).start();
}
}
public static class ReadThread extends Thread {
public ReadThread(String fileName) {
super(fileName);
}
@Override
public void run() {
String fileName = Thread.currentThread().getName();
try (BufferedInputStream fileInStream = new BufferedInputStream(new FileInputStream(fileName))) {
Map<Integer, Integer> dataAndCount = getDataAndCount(fileInStream);
int mostFrequentData = getMostFrequentData(dataAndCount);
resultMap.put(fileName, mostFrequentData);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static Map<Integer, Integer> getDataAndCount(InputStream input) throws IOException {
Map<Integer, Integer> dataAndCount = new HashMap<>(input.available());
while (input.available() > 0) {
int data = input.read();
if (dataAndCount.containsKey(data)) {
int newCount = dataAndCount.get(data) + 1;
dataAndCount.put(data, newCount);
} else {
dataAndCount.put(data, 1);
}
}
return dataAndCount;
}
public static int getMostFrequentData(Map<Integer, Integer> dataAndCount) {
int maxCount = 0;
int result = -1;
for (Map.Entry<Integer, Integer> pair : dataAndCount.entrySet()) {
int data = pair.getKey();
int count = pair.getValue();
if (count > maxCount) {
maxCount = count;
result = data;
}
}
return result;
}
}
}