Create LineNumberReader from FileReader : LineNumberReader « File Input Output « Java






Create LineNumberReader from FileReader

    
import java.io.FileReader;
import java.io.LineNumberReader;

class LineViewer {
  public static void main(String[] args) throws Exception {
    LineNumberReader lnr = null;

    FileReader fr = new FileReader(args[0]);
    lnr = new LineNumberReader(fr);

    String s;
    while ((s = lnr.readLine()) != null)
      System.out.println(lnr.getLineNumber() + ": " + s);
  }
}

   
    
    
    
  








Related examples in the same category

1.Using the LineNumberReader to read a text file line by line
2.Line Number IO
3.Use LineNumberReader class to read file
4.Split Lines
5.Convert lines into the canonical format, that is, terminate lines with the CRLF sequence.