Tutorialspoint examples

Learn java tutorial with examples for beginners online

convert byte array to inputstream java program


Example:

package com.tutorialspointexamples;
 
import java.io.ByteArrayInputStream;
import java.io.InputStream;
 
public class ByteArrayToInputStream {
  public static void main(String args[]){
      String str = "Test Content";
      byte[] content = str.getBytes();
      int size = content.length;
      InputStream is = null;
      byte[] b = new byte[size];
      try {
          is = new ByteArrayInputStream(content);
          is.read(b);
          System.out.println("String content: "+new String(b));
      } catch (Exception e) {
          e.printStackTrace();
      } 
  }
}

Output:

String content: Test Content

Download this example.

Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status