public class Text7 {
public static void main(String[] args) throws IOException {
//读字符流
String fileName = "1.txt";
FileReader fr = new FileReader(fileName);
BufferedReader br = new BufferedReader(fr);
//写字符流
String fileNameres = "2.txt";
FileWriter frres = new FileWriter(fileNameres);
BufferedWriter bwres = new BufferedWriter(frres);
//取出文本中所有行,并追加到StringBuffer中
StringBuffer sb=new StringBuffer("");
StringBuffer sbres=new StringBuffer("");
String nextLine;
while ((nextLine = br.readLine()) != null) {
sb.append(nextLine);
}
br.close();
fr.close();
char[] a=sb.toString().toCharArray();
//判断每个字符出现的次数
for(int i=0;i<a.length;i++){
int k=0;
for(int j=0;j<a.length;j++){
if(a[i]==a[j]) k++;
}
if(sbres.toString().indexOf(String.valueOf(a[i]))<0){
String str=a[i]+":"+k+"次";
sbres.append(str+"\n");
System.out.println(str);
}
}
bwres.write(a);
bwres.newLine();
bwres.close();
frres.close();
}
}
//我用myelipse编写的。2.txt存在哪了 |