和楼上的差不多了
- BufferedReader bufr=new BufferedReader(new FileReader("D:\\a\\a.txt"));
- char ch[]=new char[1024];
- String line=null;
-
- Map<Character,Integer> map=new HashMap<Character,Integer>();
-
- while((line=bufr.readLine())!=null){
- ch=line.toCharArray();
- int num;
- for(int i=0;i<ch.length;i++){
- if(!map.containsKey(ch[i]))
- {
- map.put(ch[i], 1);
- continue;
- }
- num=map.get(ch[i]);
- num++;
- map.put(ch[i], num);
- }
-
- }
-
- Set<Map.Entry<Character,Integer>> entrySet=map.entrySet();
-
- for(Map.Entry<Character,Integer> en:entrySet)
- {
- System.out.println(en.getKey()+"..."+en.getValue());
- }
复制代码 |