Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will closing a DataInputStream also close the FileInputStream?

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

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

java.lang.OutOfMemoryError: GC overhead limit exceeded

like image 949
Adyz Avatar asked Dec 26 '12 12:12

Adyz


1 Answers

Yes, DataInputStream.close() also closes your FileInputStream.

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

    public void close() throws IOException {
        in.close();
    }
like image 80
Andremoniy Avatar answered Nov 15 '22 13:11

Andremoniy