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 3339072
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:27:01+00:00 2026-05-18T00:27:01+00:00

I am having a InputStream Object which is actually a zip file. I want

  • 0

I am having a InputStream Object which is actually a zip file. I want to change it back to zip file and save it. I am using DWR’s FileTransfer class object to receive the uploaded data from client.

FileTransfer have 3 methods, getInputStream() is one of them. It returns InputStream from FileTransfer object.

In my case, fileTransfer object holds zip file and as well as InputStream object too.
I have done, lot of searches in google. But i am not able to find one example, that illustrates InputStream to zip conversion.

Update

String zipName = file.getName();
String zipType = file.getMimeType();
InputStream zipStream = file.getInputStream();
ZipInputStream zis = new ZipInputStream(zipStream);
System.out.println("File Name: "+zipName+"\n"+"File Type: "+zipType);
int c;
File f2 = new File(DATA_STORE_LOC+dat+".zip");
path.setPath2(DATA_STORE_LOC+dat+".zip");
FileOutputStream fos = new FileOutputStream(f2);
ZipOutputStream zos = new ZipOutputStream(fos);
c = zis.read();
System.out.println(c);
while ((c = zis.read(BUFFER)) != -1) {
zos.write(BUFFER, 0, c);
}
zos.close();
zis.close();

I tried this code, by thought of a typical file copy program. I know it is false, just tried. It gives me java.util.zip.ZipException: ZIP file must have at least one entry.

Any suggestion would be really appreciative!!!!!

  • 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-18T00:27:01+00:00Added an answer on May 18, 2026 at 12:27 am

    See the examples java2s, input and output. If you have more questions feel free to ask them 🙂

    For clarity, in this input example you should do something like:

    // FileInputStream fin = new FileInputStream(args[i]);
    ZipInputStream zin = new ZipInputStream(ft.getInputStream());
    

    As Don Roby correctly said, if you just want to copy you need not know the file structure and you could use for example static IOUtils.copy(in, out) to copy the file.

    Further, if you do wish to extract the ZIP file contents, you should not plainly copy bytes. The ZIP file has a structure, and you extract Entries from the ZIP file, and not just bytes (see the example). Every Entry is a (compressed) file (or the data thereof) with the original name:

    ZipEntry ze = null;
    while ((ze = zin.getNextEntry()) != null) {
      System.out.println("Unzipping " + ze.getName());
      FileOutputStream fout = new FileOutputStream(ze.getName());
      for (int c = zin.read(); c != -1; c = zin.read()) {
      ...
    

    Please note the javadoc of getNextEntry():

    Reads the next ZIP file entry and positions the stream at the beginning of the entry data.

    This positioning is crucial to get to the zipped file contents, and not the metadata.

    And I do believe that you accidentally remove the first int:

    c = zis.read(); // removing the first
    while ((c = zis.read(BUFFER)) != -1) { // so you start with the second?
    

    I believe you mix 2 idioms:

    c = zis.read();
    while(c != -1) {
       ...
       c = zis.read();
    }
    

    and:

    int c;
    while ((c = zis.read(BUFFER)) != -1) { // so you start with the second?
      ...
    }
    

    I think you can see the difference 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problems with a stringstream object. My class has an input stream
I'm having problems setting the path of the zip file, X, in ZipFile zipfile
In java I'm having an inputstream (maybe sequenceinputstream ) containing more than one file.
I have written a program that reads in a File object (really an XML
I have a very simple class using HttpListener to receive an HTTP POST from
I've written code to automatically download a batch of files using an InputStream and
Having been a PHP developer on LAMP servers for quite a while, is there
Having a heckuva time with this one, though I feel I'm missing something obvious.
Having worked with Classic ASP for about 2 years now by creating a few
Having read the threads Is SqlCommand.Dispose enough? and Closing and Disposing a WCF Service

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.