import java.io.FileInputStream; import java.io.IOException; import java.util.Map; import java.util.TreeMap; public class Solution { public static void main(String[] args) throws IOException { Map<Integer, Integer> map = new TreeMap<>(); FileInputStream inputStream = new FileInputStream(args[0]); while (inputStream.available() > 0) { int key = inputStream.read(); if (map.get(key) == null) { map.put(key, 1); } else { map.put(key, map.get(key) + 1); } } inputStream.close(); for (Map.Entry<Integer, Integer> pair : map.entrySet()) { System.out.println(pair.getKey() + " " + pair.getValue()); } } }