zipping binary data in java

hack-club

New Member
I am trying to zip a group of binary data (result set returned from database) into a single file. Which can be downloaded via web application. Following code is used to zip the result set and write the zip file to HttpServletResponse\[code\]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 fileout.flush();out.close();os.close();\[/code\]The problem is that while unzipping the downloaded zip file using WinRar I get following error : \[quote\] File Path: Either multipart or corrupt ZIP archive\[/quote\]Can someone point out where am I making mistake?. Any help would be appreciated.[EDIT] I tried \[code\]response.setContentType("application/zip");\[/code\] but same result.
 
Top