Help me please to understand where I did mistake.
package com.codegym.task.task18.task1823;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class Solution {
public static Map<String , Integer> resultMap = new HashMap<String , Integer>();
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String input = br.readLine();
if (input.equals("exit")) {
break;
}
Thread t = new ReadThread(input);
t.start();
}
br.close();
}
public static class ReadThread extends Thread{
String fileName;
InputStream inputStream;
ArrayList<Integer> arrayList;
public ReadThread(String fileName) {
this.fileName = fileName;
}
@Override
public void run() {
try {
inputStream = new FileInputStream(fileName);
while(inputStream.available() > 0) {
int r = inputStream.read();
arrayList.add(r);
}
inputStream.close();
Collections.sort(arrayList);
int count = 1;
int tempCount;
int popular = arrayList.get(0);
int temp = 0;
for (int i = 0 ; i < arrayList.size()-1 ; i++) {
temp = arrayList.get(i);
tempCount = 0;
for (int j =1 ; j < arrayList.size() ; j++) {
if (temp == arrayList.get(j)) {
tempCount++;
}
if (tempCount > count) {
popular = temp;
count = tempCount;
}
}
}
resultMap.put(fileName, popular);
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}