美文网首页
关于java中输入流的read方法为什么返回int

关于java中输入流的read方法为什么返回int

作者: SmileMylife | 来源:发表于2019-10-17 13:51 被阅读0次

    以下是源码中的解释:

    /**
        * Reads the next byte of data from the input stream. The value byte is
        * returned as an <code>int</code> in the range <code>0</code> to
        * <code>255</code>. If no byte is available because the end of the stream
        * has been reached, the value <code>-1</code> is returned. This method
        * blocks until input data is available, the end of the stream is detected,
        * or an exception is thrown.
        *
        * <p> A subclass must provide an implementation of this method.
        *
        * @return     the next byte of data, or <code>-1</code> if the end of the
        *             stream is reached.
        * @exception  IOException  if an I/O error occurs.
        */
       public abstract int read() throws IOException;
    

    其中返回的int值代表了下一字节数据所代表的数值,由于1byte的数值范围是0-255(不考虑符号位),所以int的范围在0-255。

    相关文章

      网友评论

          本文标题:关于java中输入流的read方法为什么返回int

          本文链接:https://www.haomeiwen.com/subject/noimmctx.html