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

以下是源码中的解释:

/**
    * Reads the next byte of data from the input stream. The value byte is
    * returned as an int in the range 0 to
    * 255. If no byte is available because the end of the stream
    * has been reached, the value -1 is returned. This method
    * blocks until input data is available, the end of the stream is detected,
    * or an exception is thrown.
    *
    * 

A subclass must provide an implementation of this method. * * @return the next byte of data, or -1 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)