InputStream接口的常见实现类

一. FileInputStream

  FileInputStream可以从系统文件中获取输入字节,也从可以从诸从图象数据的的原始字节流中读取。 如果是读取字符串流,推荐使用FileReader。

感觉就是视频,音频,图象之类的文件,就用FileInputStream读取。而如果是纯文字(字符串)文件就用FileReader读取。

  

二. FilterInputStream

   对其它的InputStream输入流进行包装,将其作为基础数据源,可能会对其进行数据转换或者提供某些额外功能,对FilterInputStream对象的操作,实际上是对其包装的inputStream进行操作。

public class FilterInputStream extends InputStream {
    /**
     * The input stream to be filtered.
     */
    protected volatile InputStream in;

    /**
     * Creates a <code>FilterInputStream</code>
     * by assigning the  argument <code>in</code>
     * to the field <code>this.in</code> so as
     * to remember it for later use.
     *
     * @param   in   the underlying input stream, or <code>null</code> if
     *          this instance is to be created without an underlying stream.
     */
    protected FilterInputStream(InputStream in) {
        this.in = in;
    }
}

  

原文地址:https://www.cnblogs.com/z-qinfeng/p/11788008.html