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

Do I need to close FileOutputStream object?

Rehman Published in 2018-02-14 05:23:51Z

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

try {
} 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();

chrylis Reply to 2018-02-14 06:47:05Z

The Javadoc for the method does not mention closing the stream, so you are responsible for closing it if necessary. Note that in fact the implementation does not close the stream; in theory, this could facilitate something like implementing a serialized form.

You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO