Code:
do {
length = fis.read(b, 0, 1024);
os.write(b);
} while (length >= 1024);
That's your problem. If you check the documentation for InputStream.read(byte[], int, int) you'll notice it says:
An attempt is made to read as many as len bytes,
but a smaller number may be read, possibly zero.
So you shouldn't assume length will be 1024 as long as there is data avaiable. If we again look at the documentation for that method we'll see:
Returns:
the total number of bytes read into the buffer,
or -1 if there is no more data because the end of the stream has been reached.
So what you need to do is change the last line of that segment to:
Code:
} while (length != -1);
shmoove