Example usage for java.io LineNumberReader getLineNumber

List of usage examples for java.io LineNumberReader getLineNumber

Introduction

In this page you can find the example usage for java.io LineNumberReader getLineNumber.

Prototype

public int getLineNumber() 

Source Link

Document

Get the current line number.

Usage

From source file:LineNumberIOApp.java

public static void main(String args[]) throws IOException {
    FileReader inFile = new FileReader("LineNumberIOApp.java");
    LineNumberReader inLines = new LineNumberReader(inFile);
    String inputLine;/*from w ww  .j a v  a  2s .c  o m*/
    while ((inputLine = inLines.readLine()) != null) {
        System.out.println(inLines.getLineNumber() + ". " + inputLine);
    }
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    String str;/* ww w . j a  va 2s  .co m*/
    // create new reader
    FileReader fr = new FileReader("C:/test.txt");
    LineNumberReader lnr = new LineNumberReader(fr);

    // read lines till the end of the stream
    while ((str = lnr.readLine()) != null) {
        int i = lnr.getLineNumber();
        System.out.print("(" + i + ")");

        // prints string
        System.out.println(str);
    }
    lnr.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    LineNumberReader r = new LineNumberReader(new FileReader("yourFile.txt"));

    String line = null;//www  .j a va 2  s.co m

    while ((line = r.readLine()) != null) {
        System.out.println(r.getLineNumber() + ": " + line);
    }
    r.close();
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    FileReader fr = new FileReader("C:/test.txt");
    LineNumberReader lnr = new LineNumberReader(fr);

    // sets the current line number
    lnr.setLineNumber(100);//from www .  ja v a 2s. c o m

    // get the current line number
    int i = lnr.getLineNumber();

    // print the current line number
    System.out.print("Current line number: " + i);
    lnr.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File file = new File("data.csv");
    FileReader fr = new FileReader(file);
    LineNumberReader lnr = new LineNumberReader(fr);
    // lnr.setLineNumber(400);
    String line = "";
    while ((line = lnr.readLine()) != null) {
        System.out.println("Line Number " + lnr.getLineNumber() + ": " + line);
    }/* w  w  w . ja  va  2 s  .com*/
    fr.close();
    lnr.close();
}

From source file:LineViewer.java

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

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

    String s;//from w w w.j a v a2 s .  c  o  m
    while ((s = lnr.readLine()) != null)
        System.out.println(lnr.getLineNumber() + ": " + s);
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    FileReader fr = new FileReader("C:/test.txt");
    LineNumberReader lnr = new LineNumberReader(fr);

    // set current line number
    lnr.setLineNumber(100);//from   w ww.j a  va  2s  . c  om
    System.out.println("setLineNumber(100) is invoked");

    // get current line number
    int i = lnr.getLineNumber();
    System.out.print("Current line number: " + i);
    lnr.close();
}

From source file:MainClass.java

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

    String nextLine = null;/*from   w ww.j a v a 2  s. c  o m*/
    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();
    }
}

From source file:Main.java

static long getLineCountForFile(File file) throws IOException {
    LineNumberReader in = new LineNumberReader(new FileReader(file));
    long numLines = 0;
    while (in.readLine() != null)
        ;// w w w. j ava  2  s  . co m
    numLines = in.getLineNumber();
    in.close();

    return numLines;

}

From source file:org.jumpmind.metl.core.runtime.component.XmlReader.java

protected static void forward(int toLine, LineNumberReader lineNumberReader) throws IOException {
    while (lineNumberReader.getLineNumber() < toLine) {
        String output = lineNumberReader.readLine();
        if (output == null) {
            break;
        }/*w  w  w .  j  a va2 s  .  c  o  m*/
    }
}