Проверил на нескольких файлах, занесение максимального байта в мапу работает исправно.
Использую встроенный метод frequency, хотя видел, что решают через перебор массива. Может валидатор на это ругается?
int count = Collections.frequency(list, list.get(0));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 InterruptedException {
Scanner scanner = new Scanner(System.in);
String file = scanner.nextLine();
while (!file.equals("exit")) {
ReadThread thread = new ReadThread(file);
thread.start();
thread.join();
file = scanner.nextLine();
}
}
public static class ReadThread extends Thread {
public static volatile String fileName;
public ReadThread(String fileName) {
this.fileName = fileName;
}
// implementing file reading
@Override
public void run() {
try {
FileInputStream in = new FileInputStream(fileName);
ArrayList<Integer> list = new ArrayList<>();
while (in.available() > 0) {
int nextByte = in.read();
list.add(nextByte);
}
in.close();
int count = Collections.frequency(list, list.get(0));
for (int next : list) {
int nextCount = Collections.frequency(list, next);
if (nextCount >= count) {
count = nextCount;
}
}
resultMap.put(fileName, count);
} catch (IOException fileNotFoundException) {
fileNotFoundException.printStackTrace();
}
}
}
}