编译运行,都没有报错,就是命令行没有结果输出。
[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 int lineNumber=0;
private FileReader fr;
MyLineNumberReader(FileReader fr)
{
this.fr=fr;
}
public String myReadLine() throws IOException
{
lineNumber++;
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()
{
return lineNumber;
}
public void myClose() throws IOException
{
fr.close();
}
}[/code] |