Сделал проверку sout-ом, все считает верно, но записывает значение не в свой файл, а в другой. Иногда не видит значения
package com.javarush.task.task18.task1823;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
/*
Нити и байты
*/
public class Solution {
public static Map<String, Integer> resultMap = new HashMap<String, Integer>();
public static int b;
public static void main(String[] args) throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
String s;
while (true) {
s = br.readLine();
if (s.equals("exit")) {
break;
}
else {
ReadThread readThread = new ReadThread(s);
readThread.start();
}
}
}
//proverka
//System.out.println(resultMap);
}
public static class ReadThread extends Thread {
FileInputStream file;
String s;
public ReadThread(String fileName) throws FileNotFoundException {
//implement constructor body
file = new FileInputStream(fileName);
this.s = fileName;
}
// implement file reading here - реализуйте чтение из файла тут
@Override
public void run() {
try {
Map<String, Integer> map = new HashMap<String, Integer>();
int count = 1;
int max = 1;
while (file.available() > 0) {
b = file.read();
}
if (map.containsValue(b)) {
count++;
map.put(s, count);
}
else {
map.put(s,b);
}
for (int i : map.values()) {
if (max < i) {
max = i;
resultMap.put(s,b);
}
}
max = 1;
file.close();
}
catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("ne nayden file");
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}