How to close IOs?
- by blackdog
when i managed IO, i found a problem. i used to close it like this:
try {
// my code
} catch (Exception e) {
// my code
} finally{
if (is != null) {
is.close();
}
}
but the close method also would throw exception. if i have more than one IO, i have to close all of them. so the code maybe like this:
try {
// my code
} catch (Exception e) {
// my code
} finally{
if (is1 != null) {
is1.close();
}
if(is2 != null{
is2.close();
}
// many IOs
}
if is1.close() throws an exception, is2, is3 would not close itself. So i have to type many try-catch-finally to control them. is there other way to solve the problem?