import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
public class count {
public static void main(String args[]) {
HashMap<Character, Integer> result = getcharmaps();
System.out.println(result);// 打印出字符串中各字符出现的次数!
}
public static HashMap<Character, Integer> getcharmaps() {
HashMap<Character, Integer> map = new HashMap<Character, Integer>();
String s=null;
int sum = 0;//用来记录换行符
int i = 0;
try {
FileReader fr=new FileReader("D:\\实验文件夹\\统计字符频率.txt");
BufferedReader br=new BufferedReader(fr);
while((s=br.readLine())!=null){
sum++;
for (i = 0; i < s.length(); i++) {
Character c = s.charAt(i);
Integer count1 = map.get(c);
map.put(c, count1 == null ? 1 : count1 + 1);
}
}
fr.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return map;
}
}
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
public class count {
public static void main(String args[]) {
HashMap<Character, Integer> result = getcharmaps();
System.out.println(result);// 打印出字符串中各字符出现的次数!
}
public static HashMap<Character, Integer> getcharmaps() {
HashMap<Character, Integer> map = new HashMap<Character, Integer>();
String s=null;
int sum = 0;//用来记录换行符
int i = 0;
try {
FileReader fr=new FileReader("D:\\实验文件夹\\统计字符频率.txt");
BufferedReader br=new BufferedReader(fr);
while((s=br.readLine())!=null){
sum++;
for (i = 0; i < s.length(); i++) {
Character c = s.charAt(i);
Integer count1 = map.get(c);
map.put(c, count1 == null ? 1 : count1 + 1);
}
}
fr.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return map;
}
}