Here we will learn the conversion of an input stream into a byte array.
To convert the InputStream into a ByteArray first we read a file from the system by using FileInputStream. Since class InputStream is super class of the FileInputStream so we can store file into InputStream to take the file as input stream. To convert the input stream into string we use toString() method and then we use the method getBytes() to convert the string into byte array. Finally we display the string as output.
The code of the program is given below:
The output of the program is given below:
106 97 118 97 46 105 111 46 70 105
108 101 73 110 112 117 116 83 116 114
101 97 109 64 51 101 50 53 97 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.