The Java IO Stream has always been a headache for me (I didn't have a system to learn Java, what I would normally need to do to see the document).
Recently encountered a requirement: read a file byte by byte. A lot of methods on the Web, code a whole bunch. I'm here to share with you a simple approach (at least for my needs to be effective).
File file= new file (fileName); FileName is the file directory, please set
inputstream in= null;
Byte[] bytes= null;
in = new FileInputStream (file); What really needs to be used is the read () method of the FileInputStream class
bytes= new Byte[in.available ()]; In.available () is the number of bytes
in.read (bytes) that gets the file; Fill the file byte one by one into the bytes array
in.close (); Remember to close in
Of course, you'll need to handle the anomalies in the middle. Since everyone has different needs for handling exceptions, try Catch is omitted here ~ ~ ~
In.available () The number of bytes to get small files is OK, but large files have not been tried. But it should be OK, otherwise the meaning of this method???
The above Java reading file by byte is a simple example of the small series to share all the content, I hope to give you a reference, but also hope that we support the cloud habitat community.