Example usage for java.io LineNumberReader read

List of usage examples for java.io LineNumberReader read

Introduction

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

Prototype

@SuppressWarnings("fallthrough")
public int read() throws IOException 

Source Link

Document

Read a single character.

Usage

From source file:Main.java

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

    int i;//from   ww  w  . j a v a  2  s  . c  o m

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

    while ((i = lnr.read()) != -1) {
        // converts int to char
        char c = (char) i;

        // prints character
        System.out.println(c);
    }
    lnr.close();
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    int i;//from w  w  w .  jav a2 s  .  com
    // create new reader
    FileReader fr = new FileReader("C:/test.txt");
    LineNumberReader lnr = new LineNumberReader(fr);

    // read till the end of the stream
    while ((i = lnr.read()) != -1) {
        // skip one byte
        lnr.skip(1);

        // converts integer to char
        char c = (char) i;

        // prints char
        System.out.print(c);
    }
    lnr.close();
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    int i;/* w  ww .ja  v  a2s .  c om*/
    // create new reader
    FileReader fr = new FileReader("C:/test.txt");
    LineNumberReader lnr = new LineNumberReader(fr, 200);

    // read till the end of the stream
    while ((i = lnr.read()) != -1) {
        // skip one byte
        lnr.skip(1);

        // converts integer to char
        char c = (char) i;

        // prints char
        System.out.print(c);
    }
    lnr.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);

    // reads and prints data from reader
    System.out.println((char) lnr.read());
    System.out.println((char) lnr.read());

    // mark invoked at this position
    lnr.mark(0);/* w ww  .ja v a2  s .c om*/
    System.out.println("mark() invoked");
    System.out.println((char) lnr.read());
    System.out.println((char) lnr.read());

    // if this reader supports mark() an reset()
    if (lnr.markSupported()) {
        // reset() repositioned the stream to the mark
        lnr.reset();
        System.out.println("reset() invoked");
        System.out.println((char) lnr.read());
        System.out.println((char) lnr.read());
    }
    lnr.close();
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    // create new reader
    FileReader fr = new FileReader("C:/test.txt");
    LineNumberReader lnr = new LineNumberReader(fr);

    // reads and prints data from reader
    System.out.println((char) lnr.read());
    System.out.println((char) lnr.read());

    // mark invoked at this position
    lnr.mark(0);// ww  w.j  a  v  a  2s. c  om
    System.out.println("mark() invoked");
    System.out.println((char) lnr.read());
    System.out.println((char) lnr.read());

    // if this reader supports mark() an reset()
    if (lnr.markSupported()) {
        // reset() repositioned the reader to the mark
        lnr.reset();
        System.out.println("reset() invoked");
        System.out.println((char) lnr.read());
        System.out.println((char) lnr.read());
    }
    lnr.close();
}

From source file:com.github.nlloyd.hornofmongo.action.MongoScriptAction.java

private boolean isOneLine(final String script) {
    LineNumberReader lnr = new LineNumberReader(new StringReader(script));
    try {/* w w  w.ja va  2s . c om*/
        @SuppressWarnings("unused")
        int lastRead;
        while ((lastRead = lnr.read()) != -1) {
        }
    } catch (IOException e) {
    }
    // 0 lines just means no line terminator in the string
    return lnr.getLineNumber() <= 1;
}