Reputation: 41
So of course we must try-catch-finaly any Closable resource.
But I came across some code which sins as follows:
java.util.Properties myProps = ... reads & loads (and doesn't close Stream!)
myProperties.store(new FileOutputStream(myFilePath), null);
System.exit(0);
java.util.Properties.store()
flushes the underlying stream (the FileOutputStream
)
Will this be enough?
Can you think of a scenario where the file won't be written? assuming that the method passes and no exception is being thrown in 'store'
Upvotes: 0
Views: 187
Reputation: 310840
It is enough in this specific case, but it is nevertheless very bad practice. The FileOutputStream
should be closed, not merely flushed.
Upvotes: 1
Reputation: 12538
If you don't want open file references I would close the streams. Flushing only makes sure that all changes are written to file.
Upvotes: 0