平常开发中,都知道要在finlly里关闭流,但是有时finlly里代码不当,会引起另外的异常。
有两点注意:
(1)判断流是否为空。
(2)filly里要捕获异常
InputStream in = null;
try {
in = settingsUrl.openStream();
settings.load(in);
} catch (IOException e) {
throw new StrutsException("Could not load " + name + ".properties:" + e, e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException io) {
//log
}
}
}