当把程序中的"L.java"改为"22.txt"后,程序能运行,但不会输出任何结果。(声明:当前目录下存在22.txt文件)[code=java]import java.io.*;
class L
{
public static void main(String args[]) throws IOException
{
FileReader fr=new FileReader("L.java");
MyBufferedReader mfr=new MyBufferedReader(fr);
String line=null;
while((line=mfr.myReadLine())!=null)
{
System.out.println(line);
}
mfr.myClose();
}
}
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);
}
return null;
}
public void myClose() throws IOException
{
r.close();
}
}[/code] |