我正在尝试使用 FilterInputStream 但我无法使其工作。如果我编写一个 FilterReader 一切顺利:
import java.io.*;
class Filter extends FilterReader {
Filter(Reader in) {
super(in);
}
public int read() throws IOException {
return 'A';
}
}
public class TestFilter {
public static void main(String[] args) throws IOException {
Reader in = new Filter(new InputStreamReader(System.in));
System.out.println((char)in.read());
}
}
执行是 A
但如果我使用 FiterInputStream,执行块读取:
import java.io.*;
class Filter extends FilterInputStream {
Filter(InputStream in) {
super(in);
}
public int read() throws IOException {
return 'A';
}
}
public class TestFilter {
public static void main(String[] args) throws IOException {
Reader in = new InputStreamReader(new Filter(System.in));
System.out.println((char)in.read());
}
}