When we need to close the output stream, we have two options.
closeQuietly means closing the stream without exception.
try { close(out) } catch(IOException e) { }
close
try { close(out) } catch(IOException e) { throw anException; }
as you know, the output stream will write / several characters to the end of the file when closing, if these records go wrong, the file also cannot be opened correctly, for example ZipoutputStream.
If I use the first, I will get some risk of breaking the closure. if I use the second, it will allow my code to be unfriendly.
Can someone give me some advice?
Sorry for describing the issue unclear.
I meant how to safely get an I / O operation. if the release of the resource did not work, it will inform the caller about it.
Thanks for your reply. And especially thanks to @Don Roby for giving me a link that contains the best answer posted by @Fabian Barney
Mr rain
source share