本文介绍了为什么InputStream#read()返回一个int而不是一个字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么 InputStream #read() 返回 int 而不是字节?
推荐答案因为字节只能保留-128直到127,而它应该返回0到255(当没有字节时返回-1(即EOF))。即使它返回 byte ,也没有空间来表示EOF。
Because a byte can only hold -128 until 127, while it should return 0 until 255 (and -1 when there's no byte left (i.e. EOF)). Even if it returned byte, there would be no room to represent EOF.
一个更有趣的问题是为什么它不返回短。
A more interesting question is why it doesn't return short.
更多推荐
为什么InputStream#read()返回一个int而不是一个字节?
发布评论