Java IO:为什么InputStream只能读一次

http://zhangbo-peipei-163-com.iteye.com/blog/2021879

InputStream的接口规范就是这么设计的。

/** 
     * 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. 
     */  

所有InputStream可以看做是一个数据通道,并不负责数据的存储和处理。

posted @ 2018-03-31 07:56  Hibou  阅读(1096)  评论(0编辑  收藏  举报