Following is part of the some code. I need to close out resources in finally clause. Do I need to call closeEntry() first or close()? I am getting some error messages.
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)
The code
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);
}
}
}