Read from the File File File
FileInputStream INPUT We obtain data values. Didn’t the
Available method, should not return the number of available bits as well as the second design?
file contains the following text:
Answer 1, Authority 100%
.available ()does not block the execution thread when there is no data, and
.available ()Returns approximate number available for reading bytes, and
.read (byte  b)– the amount of read buffer (byte array), from
-1When the end of the data stream is reached and up to the size of the array (
.available ()only checks the presence of data, and
.read ()– read them.
input.read (new byte [input.read ()]) :
- one byte is read from the stream using
- its value (in this case, the code of the
106), which returns
.read ()(it is the first byte value, and Not the amount of bytes), used to create an array of 106 bytes.
- In this byte array, data from flow is read.
- data in the stream remained 8 bytes (the first was already read in paragraph 1), and in the buffer they enter (
106 & gt; 8), so
.read (BYTE  B )Returns the amount of read bytes – 8.
The second way can not return the value greater than the size of the array.
p.s. To get the length of the file, use
new file ("Your File"). length ();