public static void main(String[] args) throws IOException {
File file = new File("src");
HashMap<Character, Integer> map = new HashMap<Character, Integer>();
p(file, map);
Set<Entry<Character,Integer>> entrySet = map.entrySet();
for (Entry<Character, Integer> entry : entrySet) {
System.out.println(entry.getKey()+"("+entry.getValue()+")");}}
private static void p(File f, HashMap<Character, Integer> map) throws IOException {
if (f.isDirectory()) {
File[] files = f.listFiles();
for (File file : files) {
if (file.isFile()) {
if (file.getName().endsWith("java")) {
BufferedReader br = new BufferedReader(new FileReader(file));
String shu;
while ((shu = br.readLine()) != null) {
char[] a = shu.toCharArray();
for (char c : a) {
if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z') {
map.put(c, map.get(c) == null ? 1 : (map.get(c) + 1));}}}}
} else {
p(file, map);}}}}}
哇,回去抄代码去了
|
|