When we need close an output stream, we have two choices.
closeQuietly means close a stream with no exception throwing up.
try { close(out) } catch(IOException e) { }
close
try { close(out) } catch(IOException e) { throw anException; }
as known, output stream will write a/several chars into the end of file when closing, if these writing goes wrong, the file also can't be open correctly such as ZipoutputStream.
if I use the first one, I will get some risk of fail closing. if I use the second one, it will let my code unfriendly.
Could someone give me some advices?
So sorry for describing the issue unclearly.
I meant that how to get an IO operation safely. if a resource's release gets failed, it would let caller know.
Thanks for all your answer. And especially thank @Don Roby for giving me a link which contains the best answer answered by @Fabian Barney
catch(IOException e) { throw anException; }
is pointless - you'd need to declarethrows IOException
to do that, so you might as well skip the try/catch – Coequal