本帖最后由 李娟 于 2011-12-22 18:50 编辑
class MyBufferedReader
{
private FileReader r;
MyBufferedReader(FileReader 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) //如果没有这两行,运行结果也是4个数据
return sb.toString();
return null;
} |