LineNumberReader: readLine() : LineNumberReader : java.io : Java by API examples (example source code) Organized by topic

Java by API
C++
PHP
Java by API Home »  java.io   » [  LineNumberReader  ]   
 



LineNumberReader: readLine()

import java.io.InputStreamReader;
import java.io.LineNumberReader;

public class MainClass {

  public static void main(String[] argsthrows Exception {
    LineNumberReader lineCounter = new LineNumberReader(new InputStreamReader(System.in));

    String nextLine = null;
    System.out.println("Type any text and press return. Type 'exit' to quit the program.");
    try {
      while ((nextLine = lineCounter.readLine()).indexOf("exit"== -1) {
        if (nextLine == null)
          break;
        System.out.print(lineCounter.getLineNumber());
        System.out.print(": ");
        System.out.println(nextLine);
      }
    catch (Exception done) {
      done.printStackTrace();
    }
  }
}
           
       
Related examples in the same category
1.  new LineNumberReader(Reader in)
2.  LineNumberReader: getLineNumber()
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.