java.io.InputStream
JAVA 输入流文件
一、继承关系
继承了closeable接口 close方法 数据在流中传输结束,需要关闭流释放空间
二、方法解读
/**
* 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.
* 核心方法
*
* 从打开的bytes流中读取bytes 并返回读取到的 int 值 (0到255)
* 如果读到了末尾 返回 -1
* 方法会阻塞直到 获取可读数据 or 流结尾 or throw exception
* 抽象方法子类必须实现
*/
public abstract int read() throws IOException;
/**
* 读取bytes 并保存到 入参b[]中
*/
public int read(byte b[]) throws IOException {
return read(b, 0, b.length);
}
/**
* 该方法循环调用read()方法读取 从 off(开始位置) 开始读取 len 长度bytes 保存到b[]中
*/
public int read(byte b[], int off, int len) throws IOException
/** 跳过长度为n的bytes */
public long skip(long n) throws IOException
/**
mark、reset、markSupported 方法通常一起使用,
mark方法会根据参数readlimit来对流进行标记
reset方法会返回标记位开始进行读取
前提是markSupported 需要返回 true
在InputStream中 markSupported默认返回false 所以mark和reset 没有实现
*/
public synchronized void mark(int readlimit) {}
public boolean markSupported() {
return false;
}
public synchronized void reset() throws IOException {
throw new IOException("mark/reset not supported");
}