Example usage for java.io FilterReader read

List of usage examples for java.io FilterReader read

Introduction

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

Prototype

public int read(char cbuf[], int off, int len) throws IOException 

Source Link

Document

Reads characters into a portion of an array.

Usage

From source file:Main.java

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

    char[] cbuf = new char[6];
    int i = 0;/*from w w w  . ja v  a2s  . c o m*/

    Reader r = new StringReader("ABCDEF");

    FilterReader fr = new FilterReader(r) {
    };

    // read data of len 4, to the buffer
    i = fr.read(cbuf, 2, 4);
    System.out.println("No. of characters read: " + i);

    // read till the end of the char buffer
    for (char c : cbuf) {
        // checks for the empty character in buffer
        if ((byte) c == 0)
            c = '-';

        System.out.print(c);
    }

}