zipファイルを作成するために使用しているコードは次のとおりです。
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream out = new ZipOutputStream(baos);
try {
for(int i=0; i<docId.length; i++){
BoxDotComDocumentManager docman = new BoxDotComDocumentManager();
Document d = docman.get(docId[i]);
ZipEntry entry = new ZipEntry(d.getFileName());
entry.setSize(d.getFileBytes().length);
out.putNextEntry(entry);
out.write(d.getFileBytes());
resp.setContentType("application/zip");
resp.setHeader("Content-Disposition", "attachment; filename="+ "zipdemo.zip");
out.closeEntry();
}
} catch (Exception e) {
System.out.println("E = " + e);
}
try {
resp.getOutputStream().write(baos.toByteArray());
resp.flushBuffer();
} catch (IOException e) {
e.printStackTrace();
}
finally {
baos.close();
out.close();
}
zip ファイルはブラウザに返されてダウンロードされますが、ファイルをダウンロードしようとすると、zip ファイルが無効であるためファイルをダウンロードできないというエラーが表示されます。
ドキュメントは、実際のファイルを含むファイルに関するすべての情報を含むオブジェクトです。
私が間違っていることについてのアイデアはありますか?私はこれの多くの順列を試しましたが、どれもうまくいかないようです。前もって感謝します。
キース