Все работает правильно, ищется байт, максимально встречающийся, и он заносится в resultMap. Подскажите, что не так?
package com.javarush.task.task18.task1823;
import java.util.*;
import java.io.*;
/*
Нити и байты
*/
public class Solution {
public static Map<String, Integer> resultMap = new HashMap<String, Integer>();
public static void main(String[] args){
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName;
while (!(fileName = reader.readLine()).equals("exit")){
new ReadThread(fileName).start();
}
reader.close();
} catch (IOException e){}
}
public static class ReadThread extends Thread {
private static volatile String fileName;
public ReadThread(String fileName) {
this.fileName = fileName;//implement constructor body
}
public void run(){
try {
FileInputStream inputStream = new FileInputStream(fileName);
ArrayList<Byte> bytes = new ArrayList<>();
TreeMap<Byte, Integer> map = new TreeMap<>();
int i;
try {
while ((i = inputStream.read())!= -1){
bytes.add((byte)i);
}
int count = 0;
for (Byte b: bytes){
count = Collections.frequency(bytes, b);
map.put(b, count);
count = 0;
}
int maxValue = Collections.max(map.values());
for (Map.Entry<Byte, Integer> pair: map.entrySet()){
if (pair.getValue().equals(maxValue)){
int b = (int) pair.getKey();
resultMap.put(fileName, b);
}
}
inputStream.close();
} catch (IOException e){}
} catch (FileNotFoundException e){}
}// implement file reading here - реализуйте чтение из файла тут
}
}