In this example we are going to convert InputStream to ByteArrayInputStream.
To do so first read the file as input stream using FileInputStream. Then convert this input stream into string and then string into byte by using the toString() and getBytes() methods respectively. Pass the reference of the byte array into a ByteArrayInputStream class object. This makes the conversion of the byte array into the ByteArrayInputStream. Finally we are printing this ByteArrayInputStream.
The code of the program is given below:
import java.io.*;
|
The output of the program is given below:
C:\rajesh\io>javac InputStreamToByteArrayInputStream.java C:\rajesh\io>java InputStreamToByteArrayInputStream 97 97 105 46 105 101 110 117 83 114 97 64 101 53 53....... |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Convert Inputstream to ByteArrayInputStream View All Comments
Post your Comment