CodesJava

Easy learning with example program codes

convert byte array to inputstream java program

Example:

package com.codesjava;
 
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:
error
Posted in IO   








Copyright © 2019 CodesJava DMCA.com Protection Status