public class Test02 {
public static void main(String[] args) throws IOException {
File file = new File("stu.txt");
int count = getNum(file, 'a');
System.out.println("'a'出现了" + count + "次");
}
public static int getNum(File file, char a) throws IOException {
int count = 0;
FileInputStream fis = new FileInputStream(file);
int len;
while ((len = fis.read()) != -1) {
if (a == (char) len) {
count++;
}
}
return count;
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |