import java.io.*;
class MyBufferedReader extends Reader {
private Reader r;
MyBufferedReader(Reader r) {
this.r = r;
}
public String myReadLine() throws IOException {
StringBuilder sb = new StringBuilder();
int ch = 0;
while ((ch = r.read()) != -1) {
if (ch == '\r')
continue;
if (ch == '\n')
return sb.toString();
else
sb.append((char) ch);
}
if (sb.length() != 0)
return sb.toString();
return null;
}
public void myClose() throws IOException {
r.close();
}
/*
* 覆盖Reader类中的抽象方法。
*/
public int read(char[] cbuf, int off, int len) throws IOException {
return r.read(cbuf, off, len);
}
public void close() throws IOException {
r.close();
}
}
自定义装饰类
最新推荐文章于 2022-11-14 16:23:15 发布