package com;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
public class BufferedReaderDemo {
public static void main(String[] args) throws Exception {
int cnt1=0,cnt2=0;
BufferedReader br = new BufferedReader(new FileReader(new File("c:\\test.txt")));
String str="";
while((str = br.readLine())!=null){
for(int i=0;i<str.length();i++) {
if(str.charAt(i)=='A')
cnt1++;
if(str.charAt(i)=='a')
cnt2++;
}
}
br.close();
String s = "大写字母A的次数是:"+cnt1+",小写字母a的次数是:"+cnt2;
System.out.println(s);
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("d:\\result.txt")));
bw.write(s, 0, s.length());
bw.close();
}
}