Jesper de Jong wrote:If you look at the API documentation of class BufferedOutputStream, you'll see that it inherits its close() method from FilteredOutputStream. And the documentation of the close() method for FilteredOutputStream says:
Closes this output stream and releases any system resources associated with the stream.
The close method of FilterOutputStream calls its flush method, and then calls the close method of its underlying output stream.
So you do not need to flush the stream explicitly or call close on on the underlying FileOutputStream.
You get a problem because you close the FileOutputStream in line 29, before your close the BufferedOutputStream in line 30. If you close the FileOutputStream first, then BufferedOutputStream can't flush the data anymore that it still might have in its buffer. So, the solution is to not close the FileOutputStream yourself; just let the BufferedOutputStream do that.
Make the finally-block look like this: