本帖最后由 邝雄伟 于 2013-2-2 23:46 编辑
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();// 问题,请问这里return了容器里面的数据之后,容器是不是清空了,求解释
else
sb.append((char)ch);
}
if(sb.length()!=0)
return sb.toString();
return null;
}
|