convert byte array to inputstream java program

Example:

package com.w3spoint;
 
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.

Please follow and like us:
Content Protection by DMCA.com