Home Do I need to close FileOutputStream object?
Reply: 0

Do I need to close FileOutputStream object?

user1088
1#
user1088 Published in June 19, 2018, 4:09 pm

In my code I am using a Apache POI library class - HSSFWorkbook.

try {
    testBook.write(outputStream);
} catch (Exception e) {
    throw new ExportException(e);
}

As you can see I am passing a FileOutputStream object to the write() method. My question is, is there any need of closing this stream object in a finally block or POI does it internally ?

I have seen that POIFSFileSystem.writeFilesystem() method is called from HSSFWorkbook.write() method and in writeFilesystem() method following code is written where stream object is getting passed to writeBlocks() method. But I am not sure at runtime which instance of which class writer variable will refer to. So I dont know at the end what is happening to that stream object.

Please help.

iter = writers.iterator();
while (iter.hasNext())
{
    BlockWritable writer = ( BlockWritable ) iter.next();

    writer.writeBlocks(stream);
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.422272 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO