Доброго времени суток! Для каждой новой нити инициализирую поток чтения в конструкторе. Почему валидатор не видит этого не понимаю.
package com.javarush.task.task18.task1823;
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
/*
Нити и байты
*/
public class Solution {
public static Map<String, Integer> resultMap = new HashMap<String, Integer>();
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (!reader.readLine().equals("exit")) {
new ReadThread(reader.readLine()).start();
}
}
public static class ReadThread extends Thread {
String filename;
int[] numArray;
FileInputStream fileInputStream;
File file;
public ReadThread(String fileName) throws FileNotFoundException {
this.filename = fileName;
file = new File(this.filename);
numArray = new int[256];
fileInputStream = new FileInputStream(file);
}
@Override
public void run() {
try {
while (fileInputStream.available() > 0) {
int count = fileInputStream.read();
numArray[count]++;
}
int max = Collections.max(Arrays.stream(numArray).boxed().collect(Collectors.toList()));
int index = 0;
for (int i = 0; i < numArray.length; i++) {
if (numArray[i] == max) {
index = i;
}
}
resultMap.put(filename, index);
fileInputStream.close();
} catch (IOException IO) {
IO.printStackTrace();
}
}
}
}
