Would someone be willing to see if my explanation of what is happening is accurate?
1. if (inputStream.available() > 0) {
// Read the entire file in one batch
2. byte[] buffer = new byte[inputStream.available()];
3. int count = inputStream.read(buffer);
4. outputStream.write(buffer, 0, count);
}
1. Check to see if there are bytes to be read
2. Creates a byte array with the number of bytes available
3. It reads the stream "inputStream" using the read() method, with the buffer array as an argument. It saves the size of the buffer array in the count variable.
4. This writes a file using the elements (bytes) from the buffer array, and provides the size of the array from line 3.
Thanks!
Another Comprehension check
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Thomas
1 August 2021, 06:32useful
3. the read method returns the number of bytes read and not the buffer length
4. yes, but there is an overladed version of the read method taking just a byte array as argument. It writes the entire array and you do not need to provide an offset and a length. Like the read version you've chosen in 3.
0 would be the offset and count the number of bytes to write
+1