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(char cbuf[], int off, int len) throws IOException 

Source Link

Document

Read characters into a portion of an array.

Usage

From source file:Main.java

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

    char[] cbuf = new char[5];

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

    // read characters into the buffer
    int i = lnr.read(cbuf, 2, 3);
    System.out.println("Number of char read: " + i);

    // for each character in the buffer
    for (char c : cbuf) {
        // if char is empty
        if ((int) c == 0)
            c = '-';

        // prints char
        System.out.print(c);/*from  w ww  .j  a va 2s.  c o m*/
    }
    lnr.close();
}