【发布时间】:2010-07-28 14:46:51
【问题描述】:
如果我在 servlet 中有以下代码:
Properties p = new Properties();
p.load(getClass().getResourceAsStream("/test.properties"));
如果我通过 FindBugs 运行 servlet,我希望收到警告 OS_OPEN_STREAM,但我没有。如果我使用类似的方法打开文件系统上的任意文件(即不在类路径中),我会按预期收到 Findbugs 警告:
Properties p = new Properties();
p.load(new FileInputStream(new File("c:/test.properties")));
在第一个示例中,警告是因为 Findbugs 缺少有效警告(即我应该在加载到 Properties 对象后在 finally 块中关闭流)还是没有我不需要关闭的原因流?
谢谢
丰富
【问题讨论】: