package io; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; public class First { public static void main(String[] args) throws IOException { int a=0;int b=0;int c=0;int d=0;int e=0;int f=0;int g=0;int h=0;int i=0;int j=0;int k=0;int l=0;int m=0;int n=0;int o=0;int p=0;int q=0; int r=0;int s=0;int t=0;int u=0;int v=0;int w=0;int x=0;int y=0;int z=0; int A=0;int B=0;int C=0;int D=0;int E=0;int F=0;int G=0;int H=0;int I=0;int J=0;int K=0;int L=0;int M=0;int N=0;int O=0;int P=0;int Q=0; int R=0;int S=0;int T=0;int U=0;int V=0;int W=0;int X=0;int Y=0;int Z=0; // 新文件 File newFile = new File("d:\\File.txt"); char[] data=new char[1000]; // 读取文件内容 File file = new File("d:\\file.txt"); BufferedReader reader = new BufferedReader(new FileReader(file)); StringBuffer sb = new StringBuffer(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line); System.out.println(line); } reader.close(); // 统计字母个数 for (int ii = 0; ii < sb.length(); ii++) { char ch = sb.charAt(ii); for(int qq=0;qq<1000;qq++) { data[qq]=ch; } for(int qq=0;qq<1000;qq++) { System.out.print(data[qq]); } if(ch=='A') { A++; } if(ch=='B') { B++; } if(ch=='C') { C++; } if(ch=='D') { D++; } if(ch=='E') { E++; } if(ch=='F') { F++; } if(ch=='G') { G++; } if(ch=='H') { H++; } if(ch=='I') { I++; } if(ch=='J') { J++; } if(ch=='K') { K++; } if(ch=='L') { L++; } if(ch=='M') { M++; } if(ch=='N') { N++; } if(ch=='O') { O++; } if(ch=='P') { P++; } if(ch=='Q') { Q++; } if(ch=='R') { R++; } if(ch=='S') { S++; } if(ch=='T') { T++; } if(ch=='U') { U++; } if(ch=='V') { V++; } if(ch=='W') { W++; } if (ch=='X') { X++; } if (ch=='Y') { Y++; } if (ch=='Z') { Z++; } if (ch=='a') { a++; } if (ch=='b') { b++; } if (ch=='c') { c++; } if (ch=='d') { d++; } if (ch=='e') { e++; } if (ch=='f') { f++; } if (ch=='g') { g++; } if (ch=='h') { h++; } if (ch=='i') { i++; } if (ch=='j') { j++; } if (ch=='k') { k++; } if (ch=='l') { l++; } if (ch=='m') { m++; } if (ch=='n') { n++; } if (ch=='o') { o++; } if (ch=='p') { p++; } if (ch=='q') { q++; } if (ch=='r') { r++; } if (ch=='s') { s++; } if (ch=='t') { t++; } if (ch=='u') { u++; } if (ch=='v') { v++; } if (ch=='w') { w++; } if (ch=='x') { x++; } if (ch=='y') { y++; } if (ch=='z') { z++; } } System.out.println("a:"+a+"\t"+"b:"+b+"\t"+"c:"+c+"\t"+"d"+d); System.out.println("e:"+e+"\t"+"f:"+f+"\t"+"g:"+g+"\t"+"h"+h); System.out.println("i:"+i+"\t"+"j:"+j+"\t"+"k:"+k+"\t"+"l"+l); System.out.println("m:"+m+"\t"+"n:"+n+"\t"+"o:"+o+"\t"+"p"+p); System.out.println("q:"+q+"\t"+"r:"+r+"\t"+"s:"+s+"\t"+"t"+t); System.out.println("u:"+u+"\t"+"v:"+v+"\t"+"w:"+w+"\t"+"x"+x); System.out.println("y:"+y+"\t"+"z:"+z+"\t"); System.out.println("A:"+A+"\t"+"B:"+B+"\t"+"C:"+C+"\t"+"D"+D); System.out.println("E:"+E+"\t"+"F:"+F+"\t"+"G:"+G+"\t"+"H"+H); System.out.println("I:"+I+"\t"+"J:"+J+"\t"+"K:"+K+"\t"+"L"+L); System.out.println("M:"+M+"\t"+"N:"+N+"\t"+"O:"+O+"\t"+"P"+P); System.out.println("Q:"+Q+"\t"+"R:"+R+"\t"+"S:"+S+"\t"+"T"+T); System.out.println("U:"+U+"\t"+"V:"+V+"\t"+"W:"+W+"\t"+"X"+X); System.out.println("Y:"+Y+"\t"+"Z:"+Z); } }