Thank you!!
package com.codegym.task.task18.task1823;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.nio.Buffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/*
Threads and bytes
*/
public class Solution {
public static Map<String, Integer> resultMap = new HashMap<String, Integer>();
public static Map<String, Integer> map = new HashMap<>();
public static void main(String[] args) throws Exception{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String file;
ReadThread thread;
while(true){
file = reader.readLine();
if (file.equals("exit"))
break;
thread = new ReadThread(file);
thread.start();
}
reader.close();
}
public static class ReadThread extends Thread {
String filename;
public ReadThread(String fileName) {
this.filename = fileName;
}
public void run() {
//String
int count = 0;
int max = 0;
Integer theMaximum = 0;
try{
FileInputStream fileInputStream = new FileInputStream(filename);
byte[] buffer = new byte[fileInputStream.available()];
fileInputStream.read(buffer);
String str = new String(buffer);
String[] array = str.split("");
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add(array[0]);
fileInputStream.close();
for (int i =0 ;i <array.length ; i++){
if(!arrayList.contains(array[i]))
arrayList.add(array[i]);
}
for (int i = 0; i < arrayList.size(); i++) {
count = 0;
for (int j = 0; j < array.length; j++) {
if (arrayList.get(i).equals(array[j])) {
count++;
}
}
String key = arrayList.get(i);
int value = count;
map.put(key, value);
}
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() > max) {
max = entry.getValue();
}
}
for (Map.Entry<String, Integer> en : map.entrySet()) {
if (en.getValue().equals(max)) {
theMaximum = Integer.parseInt(en.getKey());
}
}
resultMap.put(filename, theMaximum);
map.clear();
}catch (Exception e){e.printStackTrace();}
}
}
}