简体   繁体   English

无法下载 java 中 FireFox 中的 zip 类型文件

[英]cannot download zip type file in FireFox in java

I am unable to download zip file in Firefox browser it downloads as simple file type, on extracting able to retrieve the contents same if opened directly from browser pop up and when navigated to local folder in windows able to see in Zip. I am unable to download zip file in Firefox browser it downloads as simple file type, on extracting able to retrieve the contents same if opened directly from browser pop up and when navigated to local folder in windows able to see in Zip.

below is my code下面是我的代码

String mimeType = "application/octet-stream";
response.setContentType(mimeType);
response.addHeader("Content-Disposition", "attachment; filename=" + fileName + ".zip");

// creating byteArray stream, make it bufferable and passing this buffer
// to ZipOutputStream
ZipOutputStream zipOutputStream;
try {
zipOutputStream = new ZipOutputStream(response.getOutputStream());
} catch (IOException e1) {
throw new ItemNotFoundException("IO error downloading file");
}

int i = 1;
for (FileDTO file : fileList) {
// new zip entry and copying inputstream with file to
// zipOutputStream, after all closing streams
try {
zipOutputStream.putNextEntry(new ZipEntry(i + "_" + file.getFileName()));
IOUtils.copy(file.getFileObject().getObjectContent(), zipOutputStream);
zipOutputStream.closeEntry();
} catch (IOException e) {
throw new ItemNotFoundException("IO error downloading file");
}
i++;
}

if (zipOutputStream != null) {
try {
zipOutputStream.finish();
zipOutputStream.flush();
} catch (IOException e) {
throw new ItemNotFoundException("IO error downloading file");
}

IOUtils.closeQuietly(zipOutputStream);

Try using Content-Type - application/zip尝试使用 Content-Type - application/zip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM