一道JAVA题目 是流和文件的
来源:百度知道 编辑:UC知道 时间:2024/05/25 15:07:06
我一般是使用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);