具体症状为:编译运行都没有报错,但没有输出任何内容。高手指点[code=java]import java.io.*;
class L
{
public static void main(String args[]) throws IOException
{
FileReader fr=new FileReader("L.java");
MyLineNumberReader mlnr=new MyLineNumberReader(fr);
String line=null;
while((line=mlnr.myReadLine())!=null)
{
System.out.println(mlnr.myGetLineNumber()+" "+line);
}
mlnr.myClose();
System.out.println("love");
}
}
class MyLineNumberReader
{
private FileReader fr;
MyLineNumberReader(FileReader fr)
{
this.fr=fr;
}
public String myReadLine() throws IOException
{
StringBuilder sb=new StringBuilder();
int ch=0;
while((ch=fr.read())!=-1)
{
if((ch=fr.read())=='\r')
continue;
if((ch=fr.read())=='\n')
return sb.toString();
else
sb.append((char)ch);
}
return null;
}
public int myGetLineNumber() throws IOException
{
int lineNumber=0;
while(myReadLine()!=null)
{
System.out.println(lineNumber++);
}
return 0;
}
public void myClose() throws IOException
{
fr.close();
}
}[/code] |
|