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:
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.......
Posted on: June 21, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles