#

LineCountingBufferedReader

Häufig benötigt, einmal kurz notiert: LineCountingBufferedReader.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
 
/**
 * @author M. Serhat Cinar
 *
 */
public class LineCountingBufferedReader extends BufferedReader {
  private int count = 0;
 
  /**
   * @param in
   */
  public LineCountingBufferedReader(Reader in) {
    super(in);
  }
 
  /**
   * @param in
   * @param sz
   */
  public LineCountingBufferedReader(Reader in, int sz) {
    super(in, sz);
  }
 
  public String readLine() throws IOException{
    count++;
    return super.readLine();
  }
 
  public int getLineNumber(){
    return count;
  }
}
Tags:

Leave a Reply »»

Note: All comments are manually approved to avoid spam. So if your comment doesn't appear immediately, that's ok. Have patience, it can take some days until I have the time to approve my comments.