There is still error in this code.
Observe that variable count is never used. What's the meaning of offset + length ? What's the meaning of that while loop? It executes only once, and only once. The line in.read(array, offset, (length - offset)); never changes length or offset. When while loop is first time executed, offset is 0, and length is the length of the file, and, becaouse zero is, should be in some case, less then a length of the file, the loop starts to be executed. Before the end of the loop offset is setted to have a value of the length of the file, and becaouse of that when while loop checks again its condition, it doesn't enter into a second loop.
But what should happen is, that, it enters into another loop if the file is not read until the end, what is not done here, but that what's described.
The method read returns integer, quote from javadoc:
Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.
So... It should loop until the file is read, and that can be seen in the return value of the read method.
Everytime that something is read from the file, the number of not read bytes is smaller and smaller. The 'offset' variable should be incremented with the 'count' varible, not 'length' variable.
, or maybe like this?
But I have a question. (
?)
file.length(); returns long. Here it's casted to an integer. What if the return value is bigger than a maximum integer?