help)
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 IOException, InterruptedException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String fileName = reader.readLine();
if (fileName.equals("exit")) {
break;
}
ReadThread readThread = new ReadThread(fileName);
readThread.start();
readThread.join();
}
}
public static class ReadThread extends Thread {
private String fileName;
static Map<String, Integer> resultMap = new HashMap<>();
public ReadThread(String fileName) {
this.fileName = fileName;
//implement constructor body
}
public void run() {
try {
FileInputStream fileInputStream = new FileInputStream(fileName);
HashMap<Integer, Integer> map = new HashMap<>();
int count = 1;
while (fileInputStream.available() > 0) {
int b = fileInputStream.read();
if (map.containsKey(b)) {
int thisCount = map.get(b) + 1;
map.replace(b, thisCount);
} else {
map.put(b, count);
}
}
fileInputStream.close();
int maxValues = 0;
for (Map.Entry<Integer, Integer> pair : map.entrySet()) {
int max = pair.getValue();
if (max > maxValues) {
maxValues = max;
}
}
for (Map.Entry<Integer, Integer> pair : map.entrySet()) {
if (pair.getValue().equals(maxValues)) {
resultMap.put(fileName, pair.getKey());
}
}
// for (Map.Entry<String, Integer> pair: resultMap.entrySet()){
// System.out.println(pair.getKey()+" "+pair.getValue());
// }
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
// implement file reading here - реализуйте чтение из файла тут
}
}