import java.io.*;//导包
class MyReadLine
{
private Reader r;????
MyReadLine(Reader r)
{
this.r = r;
}
public String myReadLine()
{
StringBuilder sb = new StringBuilder();//创建容器
int num = 0;
try
{
while ((num = r.read())!=-1)//-1
{
if(num=='\r')//字符
continue;
if(num=='\n')
return sb.toString();
sb.append((char)num);
}
}
catch (IOException e)
{
}
if(sb.length()!=0)//是0不是null
return sb.toString();//??????
return null;//???????
}
public void myClose()
{
try
{
if (r!=null)
{
r.close();
}
}
catch (IOException e)
{
}
}
}
class MyReadLineDemo
{
public static void main(String[] args)
{
Reader s = null;
MyReadLine ml = new MyReadLine(s);
char[] ch = new char[1024];
String str ;
try
{
s=new FileReader("hang.txt");
while ((str = ml.myReadLine())!=null)
{
System.out.println(str);
}
}
catch (IOException e)
{
}
ml.myClose();
}
}
基础视频自定义字符缓冲区 ,不明白的是为什么会有带问号的两个return返回值?
|
|