import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
class MyLineNumberReader
{
private BufferedReader br;
private int LineNumber;
MyLineNumberReader(BufferedReader br)
{
this.br=br;
}
public void setLineNumber(int LineNumber)
{
this.LineNumber=LineNumber;
}
public int getLineNumber()
{
return ++LineNumber;
}
public String readLine()throws IOException
{
return br.readLine();
}
public void myClose()
{
try
{
br.close();
}
catch (IOException e)
{
System.out.println("缓冲区资源关闭失败"+e.toString());
}
}
}
class MyLineNumberReaderTest
{
public static void main(String[] args)
{
BufferedReader br=null;
MyLineNumberReader mlnr=null;
try
{
br=new BufferedReader(new FileReader("DateTest.Java"));
mlnr=new MyLineNumberReader(br);
mlnr.setLineNumber(100);
for (String line=null;(line=mlnr.readLine())!=null ; )
{
System.out.println(mlnr.getLineNumber()+":"+line);
}
mlnr.myClose();
}
catch (IOException e)
{
System.out.println("设置行号读取失败"+e.toString());
}
}
}
//上面代码中有一处代码如何进行处理呢?请各位大牛帮忙指点下,谢了:lol
public String readLine()throws IOException
{
return br.readLine();
} |
|