Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6950359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:04:58+00:00 2026-05-27T14:04:58+00:00

I am trying to zip a group of binary data (result set returned from

  • 0

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

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();

The problem is that while unzipping the downloaded zip file using WinRar I get following error :

File Path: Either multipart or corrupt ZIP archive

Can someone point out where am I making mistake?. Any help would be appreciated.

[EDIT] I tried response.setContentType("application/zip"); but same result.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:04:58+00:00Added an answer on May 27, 2026 at 2:04 pm

    The following code works for me:

    FileOutputStream os = new FileOutputStream("out.zip");
    ZipOutputStream zos = new ZipOutputStream(os);
    try
    {
        for (int i = 1; i <= 5; i++)
        {
            ZipEntry curEntry = new ZipEntry("file" + i + ".txt");
            zos.putNextEntry(curEntry);
            zos.write(("Good morning " + i).getBytes("UTF-8"));
        }
    }
    finally
    {
        zos.close();
    }
    

    Zip files generated with this code opens up with 7-zip without problem.

    • Check that the response from the servlet is not actually a 404 or 500 error page. Pick a small response and open it up with a hex editor or even a text editor. Zip files start with a ‘PK’ magic number which should be visible even in a text editor.
    • Try saving to file instead of servlet output stream for starters and see if that makes a difference.
    • Could there be a filter modifying your servlet’s output / corrupting the ZIP?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a Zip file from .Net that can be read from
I am trying to read a single file from a java.util.zip.ZipInputStream , and copy
I'm trying to create a zip file from file contents which are being piped
I am trying to zip files to an SQL Server database table. I can't
I'm trying to create a method which continually streams a zip file as a
I'm trying to create a zip file from a directory in Java, then place
I am trying to zip a long string into a file and to retrieve
I'm trying to zip a memory stream into another memory stream so I can
I'm trying to download a zip file (tl_2008_01001_edges.zip) from an ftp census site using
I am trying to stream files from a zip file using ZipEntry class in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.