Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.io.FileInputStream read() method

OrhanCemalDuruApr 1 2018 — edited Jul 31 2018

Just to vendor a thought, I wonder why the read methods of FileInputStream do not return a boolean value. Let me describe:

The description of  read(byte[], offset, length) states that it returns an integer, switching two cases:

"the total number of bytes read into buffer, or -1 if there is no more data because the eof is reached."

What if the array length is not reached after eof? The first thing that comes to my mind is that it should throw an exception, because the allocated memory of byte array is not fulfilled.

Say it returns -1 for not throwing an exception, then the byte array is full. What's the point of returning that value (the total number of bytes) which is array.length?

This post has been answered by unknown-7404 on Apr 5 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 11 2018
Added on Apr 1 2018
5 comments
3,997 views