I have tested with several ASCII symbols and it works great
package com.codegym.task.task18.task1821;
/*
Symbol frequency
*/
import java.io.*;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;
public class Solution {
public static void main(String[] args) throws IOException {
FileReader fileReader = new FileReader(args[0]);
TreeMap<Character, Integer> map = new TreeMap<>();
ArrayList<Character> charList = new ArrayList<>();
ArrayList<Integer> ASCIIlist = new ArrayList<>();
int counter = 0;
while (fileReader.ready()) {
int data = fileReader.read();
ASCIIlist.add(data);
}
fileReader.close();
for (int i = 0; i < ASCIIlist.size(); i++) {
charList.add((char)Integer.parseInt(String.valueOf(ASCIIlist.get(i))));
}
// convers bytes into chars
for (int i = 0; i<charList.size(); i++) {
if (map.containsKey(charList.get(i))) {
counter++;
map.replace(charList.get(i), counter);
}
// if map contains char counter will go up, update map
else {
map.put(charList.get(i), counter);
counter = 1;
}
// if map does not contain char, add it into map, set counter and restart counter
}
for (Map.Entry<Character,Integer> copy : map.entrySet()) {
System.out.println(copy.getKey()+ " "+copy.getValue());
}
}
}