package chapte2;
import java.io.*;
public class Duqu {
public static void main(String[] args) throws IOException {
int count = 0; //计数用的
File file = new File("D:\\1000\\hello.txt");
BufferedReader reader = new BufferedReader(new FileReader(file)); //读取文件里面的内容
StringBuffer sb = new StringBuffer(); //可变字符串类型
String line = null;
while ((line = reader.readLine()) != null) { //当每一行数据不等于空的时候,拼接到sb里面去
sb.append(line);
}
System.out.println(sb); //读取之后效果如下所示
reader.close();
// 统计字母个数
for (int i = 0; i < sb.length(); i++) {
char ch = sb.charAt(i);
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
count ++;
}
}
System.out.println(count);
}
}
效果图如下
