How to convert byte[] into inputstream?

In this article we discuss an example which explians , how to convert byte[] into input stream using Java
package com.onlinecodegeek.javase;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream; public class ByteArrToInputStream {     public static void main(String a[]){                 String str = "Welcome to awesome Java World";        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("Data Recovered after conversion : "+new String(b));        } catch (IOException e) {            e.printStackTrace();        } finally {            try{                if(is != null) is.close();            } catch (Exception ex){                             }        }             }}
OUTPUT
Data Recovered after conversion : Welcome to awesome Java World
SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment