Read byte array using ByteArrayInputStream - Java File Path IO

Java examples for File Path IO:ByteArrayInputStream

Description

Read byte array using ByteArrayInputStream

Demo Code


 
import java.io.ByteArrayInputStream;

public class Main {

  public static void main(String[] args) {

    String str = "this is a test Example!";
    byte[] bytes = str.getBytes();

    ByteArrayInputStream bai = new ByteArrayInputStream(bytes);

    int ch;/*from   www  .j  a v a2 s . co m*/

    while ((ch = bai.read()) != -1) {
      System.out.print((char) ch);
    }

  }
}

Result


Related Tutorials