Java PushbackInputStream .read (byte[] b, int off, int len)

Syntax

PushbackInputStream.read(byte[] b, int off, int len) has the following syntax.

public int read(byte[] b, int off, int len)  throws IOException

Example

In the following code shows how to use PushbackInputStream.read(byte[] b, int off, int len) method.


import java.io.*;
//from  w  w  w  . j a v  a  2  s .c o m
public class Main {

   public static void main(String[] args) {

      byte[] arrByte = new byte[1024];

      byte[] byteArray = new byte[]{'j', 'a', 'v', 'a', '2','s','.','c','o','m'};

      // create object of PushbackInputStream class for specified stream
      InputStream is = new ByteArrayInputStream(byteArray);
      PushbackInputStream pis = new PushbackInputStream(is);

      try {

         // read a char into our array
         pis.read(arrByte, 0, 3);

         // print arrByte
         for (int i = 0; i < 3; i++) {
            System.out.println((char) arrByte[i]);
         }


      } catch (Exception ex) {
         ex.printStackTrace();
      }
   }
}

The code above generates the following result.