Chain a line number reader onto a file reader. : Reader « File « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » File » Reader 
9.4.1.Chain a line number reader onto a file reader.
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;

public class MainClass {
  public static void main(String[] argv) {
    try {
      FileReader fr = new FileReader("data");
      LineNumberReader lnr = new LineNumberReader(fr);
      String s;

      while ((s = lnr.readLine()) != null) {
        System.out.println(lnr.getLineNumber() " : " + s);
      }
      lnr.close();
      fr.close();
    catch (IOException x) {
    }

  }
}
9.4.Reader
9.4.1.Chain a line number reader onto a file reader.
9.4.2.Using FileWriter and FileReader
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.