java 压缩二进制流_在java中压缩二进制数据
我試圖將一組二進制數據(從數據庫返回的結果集)壓縮到一個文件中.可以通過Web應用程序下載.以下代碼用于壓縮結果集并將zip文件寫入
HttpServletResponse
String outFilename = "outfile.zip";
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename= " + outFilename);
OutputStream os = response.getOutputStream();
ZipOutputStream out = new ZipOutputStream(os);
for (int i = 0; i < cardFileList.size(); i++) {
CardFile cardFile = cardFileList.get(i);
out.putNextEntry(new ZipEntry(cardFile.getBinaryFileName()));
out.write(cardFile.getBinaryFile(), 0, cardFile.getBinaryFile().length);
out.closeEntry();
}
// Complete the ZIP file
out.flush();
out.close();
os.close();
問題是,當使用WinRar解壓縮下載的zip文件時,我收到以下錯誤:
File Path: Either multipart or corrupt ZIP archive
有人可以指出我在哪里弄錯了嗎?任何幫助,將不勝感激.
[編輯]我試過response.setContentType(“application / zip”);但結果相同.
總結
以上是生活随笔為你收集整理的java 压缩二进制流_在java中压缩二进制数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JavaScript 操作 HTML D
- 下一篇: STM32F4_USART配置及细节描述