【问题标题】:Return type of read method in InputStream class [duplicate]InputStream类中读取方法的返回类型[重复]
【发布时间】:2012-01-17 14:07:15
【问题描述】:

为什么 InputStream 类的 read() 方法返回 int 而不是 byte?

【问题讨论】:

    标签: java


    【解决方案1】:

    如果您阅读the documentation,您会看到它解释了原因:

    值字节以 int 形式返回,范围为 0 到 255。如果由于到达流的末尾而没有可用的字节,则返回值 -1。

    【讨论】:

    • 好的,那么 OutputStream 的 write(int) 方法的 int 参数背后的原因是什么?
    • 我猜只是对称/方便。
    猜你喜欢
    • 2015-05-16
    • 2018-09-26
    • 1970-01-01
    • 1970-01-01
    • 2019-12-24
    • 1970-01-01
    • 2020-02-24
    • 2020-11-22
    • 2014-07-31
    相关资源
    最近更新 更多