Затем нити должны найти максимально встречающийся байт в своем файле и добавить его в словарь resultMap
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<>();
public static void main(String[] args) throws IOException, InterruptedException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String s = reader.readLine();
if (s.equals("exit")) break;
new ReadThread(s).start();
}
}
public static class ReadThread extends Thread {
String fileName;
public ReadThread(String fileName) {
this.fileName = fileName;
}
@Override
public void run() {
byte[] countBytes = new byte[256];
try (FileInputStream fis = new FileInputStream(fileName)) {
while (fis.available() > 0) {
countBytes[fis.read()]++;
}
} catch (IOException e) {
e.printStackTrace();
}
int max = Integer.MIN_VALUE;
for (int i = 0; i < countBytes.length; i++) {
if (max < countBytes[i]) max = i;
}
resultMap.put(fileName, max);
}
}
}