-я проверял на файлах и работает нормально.
-потоки закрыты, что уже хорошо.
-вещи типа
ArrayUtils
// или
Bytes.getIndexOf() не проходят потому что здесь их нельзя импортировать (((
может что-то не так в моей логике поиска?package com.javarush.task.task18.task1823;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.Arrays;
/*
Нити и байты
*/
public class Solution {
public static Map<String, Integer> resultMap = new HashMap<String, Integer>();
public static void main(String[] args) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));) {
while (true) {
String pathName = reader.readLine();
if (pathName.equals("exit")) {
break;
} else {
new ReadThread(pathName).start();
}
}
} catch (IOException e) {
e.printStackTrace();
}
/*for (Map.Entry<String,Integer> c: resultMap.entrySet()){
System.out.println(c.getKey()+ " "+ c.getValue());
}*/
}
public static class ReadThread extends Thread {
String fileName;
public ReadThread(String fileName) {
//implement constructor body
this.fileName = fileName;
}
@Override
public void run() {
//super.run();
try (FileInputStream fis = new FileInputStream(fileName);){
/* byte[] allbytes = new byte[fis.available()];//fis.readAllBytes();
fis.read(allbytes);*/
byte[] allbytes = Files.readAllBytes(Paths.get(fileName));
int answer = findMaxByte(allbytes);
resultMap.put(fileName,answer);
} catch (IOException e) {
e.printStackTrace();
}
// implement file reading here - реализуйте чтение из файла тут
//byte[] allbytes = new byte[fis.available()];//fis.readAllBytes();
// fis.read(allbytes);
// int answer = findMaxByte(allbytes);
}
public static int findMaxByte (byte[] byteArray){
byte[] idBase= new byte[256];
for (byte b: byteArray){
idBase[b]+=1;
}
int maxAppearedNumber =0;
int byteToReturn = 0;
for(int c=0; c<idBase.length;c++){
if (idBase[c]>maxAppearedNumber){
byteToReturn= c;
}
}
return byteToReturn;
}
}
}