Example usage for java.io FilterInputStream read

List of usage examples for java.io FilterInputStream read

Introduction

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

Prototype

public int read(byte b[]) throws IOException 

Source Link

Document

Reads up to b.length bytes of data from this input stream into an array of bytes.

Usage

From source file:Main.java

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

    byte[] buffer = new byte[6];

    // create input streams
    InputStream is = new FileInputStream("C://test.txt");
    FilterInputStream fis = new BufferedInputStream(is);

    // returns number of bytes read to buffer
    int i = fis.read(buffer);

    // prints/*from   w  w  w. j a  va2s  . c o  m*/
    System.out.println("Number of bytes read: " + i);

    // for each byte in buffer
    for (byte b : buffer) {
        // converts byte to character
        char c = (char) b;

        System.out.println("Character read: " + c);
    }

}