It's my first time I'm feeling so lost
package com.codegym.task.task18.task1823;
import java.util.HashMap;
import java.util.Map;
/*
Threads and bytes
*/
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));
String fileName = reader.readLine();
while(!fileName.equals("exit")){
ReadThread t = new ReadThread(fileName);
t.start();
t.join();
}
reader.close();
}
public static class ReadThread extends Thread {
private String fileName;
public ReadThread(String fileName) {
this.fileName = fileName;
// Implement constructor body
}
public void run(){
Map<Integer, Integer> tempMap = new HashMap<>();
int max = 0;
try(FileInputStream input = new FileInputStream(fileName)){
while(input.available()>0){
int bytes = input.read();
if(tempMap.containsKey(bytes))
tempMap.replace(bytes, tempMap.get(bytes)+1);
else
tempMap.put(bytes, 0);
}
List <Integer> list = new ArrayList<>(tempMap.values());
for(int val : list){
if(max<val)
max=val;
}
for(Map.Entry<Integer, Integer> entry : tempMap.entrySet()){
if(max==entry.getValue())
resultMap.put(fileName, entry.getKey());
}
}catch(IOException e){
}
}
}
// Implement file reading here
}