Всем привет!
Вывожу в консоль все байты, которые считываются один раз, но валидатор говорит - не то :(
Наверное, я неправильно поняла условие или не вижу какой-то очевидной ошибки, подскажите пожалуйста🙏
P.s. Сорри за вторую вкладку - смотрела Entry, теперь не знаю, как открепить от решения) Без неё тоже не валидируется.
package com.javarush.task.task18.task1804;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/*
Самые редкие байты
*/
public class Solution {
public static void main(String[] args) throws Exception {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
String pathToFile = reader.readLine();
FileInputStream fileInputStream = new FileInputStream(pathToFile);
HashMap<Byte, Integer> map = new HashMap<>();
while (fileInputStream.available() > 0) {
byte readedByte = (byte) fileInputStream.read();
if (!map.containsKey(readedByte)) {
map.put(readedByte, 1);
} else {
int i = map.get(readedByte) + 1;
map.put(readedByte, i);
}
}
fileInputStream.close();
for (Map.Entry<Byte, Integer> entry: map.entrySet()) {
if (entry.getValue() == 1) {
System.out.print(entry.getKey() + " ");
}
}
/*ArrayList<Byte> list = new ArrayList<>();
ArrayList<Integer> count = new ArrayList<Integer>();
while (fileInputStream.available() > 0) {
byte b = (byte) fileInputStream.read();
if (!list.contains(b)) {
list.add(b);
count.add(1);
} else {
int index = list.indexOf(b);
int element = count.get(index) + 1;
count.set(index, element);
}
}
fileInputStream.close();
for (int i = 0; i < count.size(); i++) {
if (count.get(i) == 1) {
System.out.print(list.get(i) + " ");
}
}*/
}
}
}