【发布时间】:2020-07-14 07:46:39
【问题描述】:
我正在编写一个批处理,下面将在循环中被调用很多次。所以我想知道我是否正确关闭了资源
//这将被循环调用
FileOutputStream fos = null;
ZipOutputStream zos = null;
try {
fos = new FileOutputStream(zipFile);
zos = new ZipOutputStream(fos);
...
...
closeQuietly(zos)
} catch(Exception e) {log.error(e.getMessage(),e);}
void closeQuietly(ZipOutputStream zos) {
try {
zos.closeEntry();
zos.flush();
zos.close();
}
catch(Exception e) {log.error(e.getMessage(),e);}
}
我是否正确关闭了资源。我还需要在closeQuietly() 中关闭FileOutputStream
【问题讨论】:
-
我建议您阅读此Oracle Document 关于您的代码风格,您的答案可能在这里:stackoverflow.com/a/8080685/4697963
标签: java zip fileoutputstream