My doubt is why can't be return type is 'byte' as it can hold value -1 ? Any clarification is appreciated. Thanks
posted 4 years ago
The method needs to be able to read a byte of data (256 possible values) or indicate there are no more values. So it needs to return 257 possibilities. A byte can only hold 256. If it returned a byte, how do you tell the difference between reading a -1 from the file and reaching the end of the stream?