【发布时间】:2021-07-15 04:55:52
【问题描述】:
此方法可能无法清理(关闭、处置)流、数据库对象或其他需要显式清理操作的资源。 一般来说,如果一个方法打开一个流或其他资源,该方法应该使用 try/finally 块来确保在方法返回之前清理流或资源。
这是代码:
public void setSource(File file) throws IOException {
m_structure = null;
setRetrieval(NONE);
if (file == null) {
throw new IOException("Source file object is null!");
}
try {
setSource(new FileInputStream(file));
}
catch (FileNotFoundException ex) {
throw new IOException("File not found");
}
m_File = file.getAbsolutePath();
}
【问题讨论】: