-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
close the outputstrean even thouht there were throwing an exception #6360
Conversation
IOUtils.copy(data, outputStream); | ||
outputStream.close(); | ||
//outputStream.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if we don't close it here, we risk an incomplete file when reading it a few statements later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,it‘s right.
but it will be closed in finally block.
if we colose here, there maybe throws an exception on before statement "IOUtils.copy(data, outputStream);".
closing it on the finally block,it will be execute in anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The finally block is too late. It needs to be closed earlier. By the time that the finally block is executed, we have already tried to read the created (incomplete) file.
No description provided.