Есть решение короче ? Укажите строку Где я уже пошел не туда
package com.javarush.task.task18.task1823;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
/*
Нити и байты
*/
public class Solution {
public static Map<String, Integer> resultMap = new HashMap<String, Integer>();
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader (new InputStreamReader(System.in));
ReadThread readThread = null;
String text;
while(!(text=reader.readLine()).equals("exit")){
readThread = new ReadThread (text);
readThread.start();
}
reader.close();
}
public static class ReadThread extends Thread {
FileInputStream fileInputStream = null;
private String fileName;
TreeMap <Integer,Integer> listMax = null;
public ReadThread(String fileName) throws Exception{
this.fileName = fileName;
fileInputStream = new FileInputStream(fileName);
//implement constructor body
}
public void run () {
listMax = new TreeMap<>();
try {
while (fileInputStream.available() > 0) {
int count = 1;
int by = fileInputStream.read();
if (listMax.containsKey(by)) {
for(Map.Entry <Integer,Integer> m : listMax.entrySet()) {
Integer i = m.getKey();
if (by == i) {
count = m.getValue() + 1;
listMax.put(by,count);
}
else {
listMax.put(by,count);
}
}
int sizeList = listMax.size();
int maxEl = Integer.MAX_VALUE;
for(HashMap.Entry <String,Integer> map: resultMap.entrySet()) {
int k = 0;
if (by == sizeList) {
maxEl = map.getValue();
}
k++;
}
resultMap.put (this.filename,maxEl);
}
}
}catch(Exception e) {
}
// implement file reading here - реализуйте чтение из файла тут
}
}
}