Not able to create ZIP file with multiple CSV - getting the exception java.base/java.io.FileOutputStream.open0(Native Method)
Hi,
I am working on a report in which I need to create a ZIP file with multiple CSV files inside it. In my local AEM instance it is working fine, but when I move my code to Dev Author instance(Cloud) I am getting this error - java.base/java.io.FileOutputStream.open0(Native Method). Below is the code snippet I am using;
String filenamePage = "/tmp/Asset-report.csv";
outZip = new ZipOutputStream(resp.getOutputStream());
try (PrintWriter writerPage = new PrintWriter(new OutputStreamWriter(new FileOutputStream(FilenameUtils.getName(filenamePage)), UTF_8))) {
writerPage.print(csvPage); //csvPage has all the content in CSV format
} catch (IOException io) {
logger.error("\n ----ERROR -----{} ", io.getStackTrace());
}
filePage = new File(FilenameUtils.getName(filenamePage));
try (FileInputStream inPage = new FileInputStream(FilenameUtils.getName(filePage.getName()))) {
outZip.putNextEntry(new ZipEntry(filePage.getName()));
int len;
while ((len = inPage.read(buf)) > 0) {
outZip.write(buf, 0, len);
}
inPage.close();
} catch (IOException io) {
logger.error("\n ----ERROR -----{} ", io.getStackTrace());
}
filePage.delete();
outZip.closeEntry();
outZip.close();
resp.flushBuffer();
Since our is Dev cloud instance, I guess when I try to create the temporary file, i don't have access to do it. Initially I give below values as temporary file name, but got the same error:
String filenamePage = "Asset-report.csv";
String filenamePage = "/content/dam/Asset-report.csv";
Please provide your suggestion and answers.
