标签:private port fileread his null 行号 get new 实现
import java.io.*;
public class MyLineNumberReader extends BufferedReader
{
private int line = 0; //行号
public MyLineNumberReader(Reader r)
{
super(r);
}
public void setLineNumber(int lineNumber)
{
this.line = lineNumber;
}
public String myReadLine() throws IOException
{
line++;
return super.readLine();
}
public int getLine()
{
return line;
}
public static void main(String[] args) throws IOException {
FileReader fr = new FileReader("buf_copy.txt");
MyLineNumberReader mlnr = new MyLineNumberReader(fr);
String line = null;
mlnr.setLineNumber(2);
while((line = mlnr.myReadLine()) != null)
{
System.out.println(mlnr.getLine() + ":" + line);
}
mlnr.close();
}
}
标签:private port fileread his null 行号 get new 实现
原文地址:https://www.cnblogs.com/coolcpp/p/linenumberreader.html