Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alekseytimoshchenko/9d3d02b38fd52d5ca8c74b73f743aed3 to your computer and use it in GitHub Desktop.
Save alekseytimoshchenko/9d3d02b38fd52d5ca8c74b73f743aed3 to your computer and use it in GitHub Desktop.
import java.io.BufferedInputStream;
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
{
if(args.length == 0){
throw new IllegalArgumentException();
}
String fileName = args[0];
Map<Character, Integer> result = new TreeMap<>();
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileName));
while (bis.available() > 0){
int tmp = bis.read();
char key = (char) tmp;
if (result.containsKey(key)){
int count = result.get(key) + 1;
result.put(key, count);
}else {
result.put(key, 1);
}
}
for (Map.Entry<Character, Integer> unit : result.entrySet()){
System.out.println(unit.getKey() + " " + unit.getValue());
}
bis.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment