Что не так? Сталкивался кто-то?
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));
String fileName;
while (!(fileName = reader.readLine()).equals("exit")){
new ReadThread(fileName).start();
}
reader.close();
}
public static class ReadThread extends Thread {
FileInputStream file;
String fileName;
public ReadThread(String fileName) throws FileNotFoundException {
//implement constructor body
this.fileName = fileName;
file = new FileInputStream(fileName);
start();
}
// implement file reading here - реализуйте чтение из файла тут
@Override
public void run() {
try {
byte[] buffer = new byte[file.available()];
file.read(buffer);
resultMap.put(fileName, (int) findMaxByte(buffer));
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static Byte findMaxByte(byte[] bytes) {
SortedMap<Byte, Integer> map = new TreeMap<>();
for (byte b : bytes) {
map.putIfAbsent(b, 1);
map.computeIfPresent(b, (key, value) -> value = ++value);
}
int count = Collections.max(map.values());
for (Map.Entry<Byte, Integer> pair : map.entrySet()) {
if (pair.getValue().equals(count))
return pair.getKey();
}
return null;
}
}