import java.io.*; import java.lang.*; public class WordStatistic { private BufferedReader br; private String s; private StringBuffer sb; private char[] c; WordStatistic(String parent,String child ) { sb=new StringBuffer(); try { br=new BufferedReader(new FileReader(new File(parent,child))); }catch (IOException e) { e.getMessage(); } } public void getWordStatistic()throws IOException { int n =0; // a-z 之间 int m=0; //A-Z 之间 int k=0; while ((s=br.readLine())!=null){ sb.append(s); } s=sb.toString(); c=s.toCharArray(); System.out.println("开始统计了:"); for(char i:c) { if(i>='a'&&i<='z') { //字符是'' n=n+1; }else if(i>='A'&&i<='Z') { m=m+1; }else { k=k+1; } } System.out.println("a-z之间的字母是:"+n+"个"); System.out.println("A-Z之间的字母是:"+m+"个"); System.out.println("不是字母的其他是:"+k+"个"); } public static void main(String[] args) throws IOException { WordStatistic ws=new WordStatistic("D:\myRead","WriteLog.txt"); ws.getWordStatistic(); } }