What is wrong? Treemap is already sorted...
package com.codegym.task.task18.task1821;
/*
Symbol frequency
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;
public class Solution {
public static void main(String[] args) throws IOException {
if (args.length > 0) {
TreeMap<String, Integer> map = new TreeMap<>();
for (char ch = 0; ch <= 255; ch++) {
map.put(String.valueOf(ch), 0);
}
//for (Map.Entry<String, Integer> en : map.entrySet()) {
// System.out.println(en.getKey() + " " + en.getValue());
//}
//File f = new File(args[0]);
FileInputStream f = new FileInputStream(args[0]);
String fcontent = "";
Scanner sc = new Scanner(f);
while (sc.hasNext()) {
String s = sc.nextLine();
fcontent = fcontent + s;
}
sc.close();
String[] ar = fcontent.split("");
for (String s : ar) {
map.put(s, map.get(s)+1);
}
for (Map.Entry<String, Integer> en : map.entrySet()) {
if (en.getValue() > 0) {
System.out.println(en.getKey() + " " + en.getValue());
}
}
f.close();
}
}
}