Created
November 12, 2016 14:01
-
-
Save alekseytimoshchenko/9d3d02b38fd52d5ca8c74b73f743aed3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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