is.read(bytes)
reads some number of bytes into the array, then returns an int with the number of bytes actually read. That value is assigned to the variable read
. Depending on the type of stream that may be a complete array-full of bytes, or some smaller number, or even, in theory, zero.
When the read() is at end of file it (obviously) doesn't read any bytes into the array, and returns a value of -1 to indicate eof. Thw while test tests for a -1 being returned, and stops looping when that happens.
eg Suppose yo have 300 bytes in a file, and a buffer size of 255
First read reads 255 bytes, returns 255, loop continues
Second read reads remaining 45 brtes, returns 45, loop continues
Third read is now at eof, reads no bytes, returns -1. Loop exits