本文介绍了关闭DataInputStream也会关闭FileInputStream吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FileInputStream fstream = new FileInputStream(someFile.getPath());
DataInputStream in = new DataInputStream(fstream);

如果我呼叫in.close(),它还会关闭fstream吗?我的代码给出了GC异常,如下所示:

If i call in.close(), will it also close fstream ? My code is giving GC Exception as follows:

java.lang.OutOfMemoryError:超出了GC开销限制

推荐答案

是的,DataInputStream.close()也会关闭您的FileInputStream.

这是因为DataInputStream继承了FilterInputStream,它具有close()方法的以下实现:

This is because DataInputStream inherits FilterInputStream which has the following implementation of the close() method:

    public void close() throws IOException {
        in.close();
    }

这篇关于关闭DataInputStream也会关闭FileInputStream吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 20:42