自定义一个BufferedReader
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
class MyBufferedReader extends Reader{
private Reader r;
MyBufferedReader(Reader r){
this.r = r ;
}
public String myReadLine()throws IOException{
int ch = 0;
StringBuilder sb = new StringBuilder();
while((ch=r.read())!=-1){
if((char)ch=='\r')
continue;
if((char)ch=='\n')
return sb.toString();
sb.append((char)ch);
}
if(sb.length()!=0)
return sb.toString();
else
return null;
}
public void myClose(Reader r)throws IOException{
r.close();
}
@Override
public int read(char[] cbuf, int off, int len) throws IOException {
return 0;
} @Override
public void close() throws IOException {
r.close();
}
}
自定义一个装饰类,但是read()如果想要自己写出实现代码能不能行呢?,是不是只能调用传进来的子类的实现方法?
|
|