- import java.io.*;
- public class MyLineNumberReader extends BufferedReader
- {
- int LineNumber = 0;
- Reader r = null;
- public MyLineNumberReader(Reader r)
- {
- super(r);
- }
-
- public int getLineNumber()
- {
- return this.LineNumber;
- }
- public void setLineNumber(int lineNumber) throws IOException
- {
- this.LineNumber = lineNumber;
- gotoLineNumber();
- //System.out.println(this.LineNumber);
- }
- public String readLine()throws IOException
- {
- String s = super.readLine();
- LineNumber++;
- return s;
- }
- private void gotoLineNumber()throws IOException
- {
- for(int i=0;i<LineNumber;i++)
- {
- super.readLine();
- }
- }
- public static void main(String[] args)throws IOException
- {
- MyLineNumberReader mln = new MyLineNumberReader(new FileReader("e:\\11.java"));
- mln.setLineNumber(5);
- String s = null;
- while((s=mln.readLine())!=null)
- {
- System.out.println(mln.getLineNumber()+" : "+s);
- }
- }
- }
复制代码
|
|