Pelr:

perl -e '$/=undef;$_=<>; printf "$&:%d\n", s/$&//g while /\S/;' test.txt

Java:

import java.util.*;
public class charCounter {  
    public static void main(String args[]){ 
        String s = "abcDFDSFDSS,adfa....****中国SSGdad";
        Map<Character, Integer> result = getCharMaps(s);
        System.out.println(result);
        
   } 
    public static Map<Character, Integer> getCharMaps(String s) {
        Map<Character, Integer> map = new HashMap<Character, Integer>();
        for(int i = 0; i < s.length(); i++) {
            Character c = s.charAt(i);
            Integer count = map.get(c);
            map.put(c, count == null ? 1 : count + 1);
        }
        return map;
    }
} 

参考:
http://topic.csdn.net/u/20071031/21/25716ed2-64b5-44a5-b335-e61ca5ee4356.html http://www.docin.com/p-44064652.html