Sonar
正在显示以下代码的错误,该错误属于阻止程序类型。它抱怨我没有关闭FileInputStream
,但我该怎么做?FileInputStream
是方法的返回类型,如果我在此处关闭,那么它从调用的地方将毫无用处。请让我知道 - 如果相同的方法返回,我该如何关闭FileInputStream
finally 块FileInputStream
?
这是代码:
@Override
public InputStream getInputStream() throws MissingObjectException {
try {
InputStream is;
if (smbFile != null) {
is = new BufferedInputStream(new SmbFileInputStream(smbFile), 60000);
}
else {
is = new BufferedInputStream(new FileInputStream(getFilePath()));
}
return is;
}
catch (Exception e) {
throw new MissingObjectException();
}
}