平常开发中,都知道要在finlly里关闭流,但是有时finlly里代码不当,会引起另外的异常。
以下是看struts2源代码看到的,随手记录下。
有两点注意:
(1)判断流是否为空。
(2)filly里要捕获异常
以下是看struts2源代码看到的,随手记录下。
有两点注意:
(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
}
}
}