以下是一些代码的一部分。我需要在 finally 子句中关闭资源。我需要先调用 closeEntry() 还是 close()?我收到一些错误消息。
Error closing the zipoutjava.io.IOException: Stream closed at
java.util.zip.ZipOutputStream.ensureOpen(ZipOutputStream.java:70) at
java.util.zip.ZipOutputStream.closeEntry(ZipOutputStream.java:189)
编码
ZipOutputStream zos = null;
try{
ZipEntry entry = new ZipEntry("file.csv")
zipout.putNextEntry(entry);
csvBeanWriter = new CsvBeanWriter(writer,
CsvPreference.STANDARD_PREFERENCE);
csvBeanWriter.writeHeader(header);
for (Book book : bookList) {
csvBeanWriter.write(book, header);
csvBeanWriterTest.write(book, header);
}
} catch (Exception e) {
logger.error("Export of package data failed: "
+ e);
} finally {
if (zipout != null) {
try {
zos.closeEntry();
zos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
logger.error("Error closing the zos"
+ e);
}
}
}