In this section, you will learn how to make a file to be read into a byte array. Here we have used inputStream constructor to take file as a parameter.
Description of code:
In this program we have taken a file which is to be read into an array of byte.
We have used file.length(); method to take the length of the file. And if
the file is very large it will give the message that the file is too large. Then
we taken two variables offset and numRead so that the file could
be read from zero. Then the file will be converted to the bytes with the help of
BytesFromFile(new File("test.txt"));.
Here is the code of program:
|
Output of the program:
| C:\chandan>javac FileReadInByteArray.java C:\chandan>java FileReadInByteArray Your File Content: Chandan Kumar Verma C:\chandan> |
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: Reading File into ByteArray View All Comments
Post your Comment