I'm trying to expand some files from a zip file. when I do it by reading one byte and writing one byte at a time it works fine but is very slow, but when I try to read the whole file and then write it with the following code the output file is severly truncated, why? what am I missing?
The call to in.read(b) is not guaranteed to fill the buffer, even though the stream should eventually provide all the bytes you expect. An InputStream may break a read into multiple parts if for some reason it's not convenient to return all the bytes at once. So this means you always need to put read(byte) or read(byte, int, int) into a loop of some sort, checking return values to see how many bytes have been read. Here's one way to do this:
Alternately, in cases where you don't know in advance what size the array will be: