Кажется слишком много циклов)
package com.javarush.task.task18.task1803;
import java.io.FileInputStream;
/*
Самые частые байты
*/
import java.sql.SQLOutput;
import java.util.*;
public class Solution {
public static void main(String[] args) throws Exception {
Scanner scan = new Scanner(System.in);
String fileName = scan.nextLine();
FileInputStream inputStream = new FileInputStream(fileName);
Map<Integer, Integer> map = new HashMap<>();
while (inputStream.available() > 0) map.put(inputStream.read(), 0);
while (inputStream.available() > 0){
int data = inputStream.read();
if(map.containsKey(data)){
map.put(data, map.get(data) + 1);
}
}
int max = 0;
List<Integer> list = new ArrayList<>(map.values());
for(Integer i : list){
if(max < i) max = i;
}
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
if(entry.getValue() == max){
System.out.print(entry.getKey() + " ");
}
}
inputStream.close();
}
}