一道JAVA题目 是流和文件的

来源:百度知道 编辑:UC知道 时间:2024/05/25 15:07:06
编制一个程序 使用READER类和WRITER类 实现对输入、输出特殊字母的计数,如输出文件中包含有多少个a,同时这个字母必须容易更改替换

我一般是使用InputStream流来读文件的
给你 这样的方法 可以调用
其中compare是判断特殊字符的次数!

import java.io.*;
public class Untitled1 {
String str=null;
int count=0;
public Untitled1() {

}
public void reader(){
InputStream file = null;
try {
file = new FileInputStream("aa.txt");
} catch (FileNotFoundException ex) {
}
BufferedReader br=new BufferedReader(new InputStreamReader(file));
try {
str = br.readLine();
int sum=compare(str);
System.out.println(sum);
file.close();
br.close();
} catch (IOException ex1) {
}

}
public void reader2(){
try {
Reader file = new FileReader("aa.txt");
BufferedReader br=new BufferedReader(file);