JAVA的输入流 - java.io.InputStream

 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");
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值