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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:33:01+00:00 2026-05-25T06:33:01+00:00

I’ve written some code that retrives a zip file and unzips it into a

  • 0

I’ve written some code that retrives a zip file and unzips it into a directoy. The zip file contains two folders and depending on what folder each file is in, it is unzipped into a folder of that directory.

However, the code takes an awful long time to run (approx 10mins). Although, the folders contain nearly 1000 files each and the total size of the zip file is 5000kb. I think its going slow because I’m creating the FileOutputStream and InputStream each time I enter the loop. However, I need to do this as I don’t know the output directory of a file until I read it from the zip file. (Ie. find out what folder it is in)

Any suggestions?

/**
 * Retrieves and unzips a file from its URL
 */
public void retrieveFiles(String URL) {

    //Retrieve file from URL
    File zip = new File(getFile(URL));
    zip.mkdirs();

    try {
        //Create .zip file from file directory
        ZipFile zipFile = new ZipFile(zip);
        Enumeration<? extends ZipEntry> enumeration = zipFile.entries();

        //While zip file contains elements, get the next zipped file
        while (enumeration.hasMoreElements()) {
            ZipEntry zipEntry = (ZipEntry) enumeration.nextElement();

            //Ignore folders and other zip files
            if(!zipEntry.isDirectory() && !zipEntry.getName().endsWith(".zip")){

                //Find directory and filename for new unzipped file
                String directory = getURL(zipEntry.getName());
                String fileName = getFileName(zipEntry.getName());
                String fullDirectory = createDirectory(directory, fileName);

                //Unzip file and store in directory
                System.out.println("Unzipping file: " + fileName);
                FileOutputStream fout = new FileOutputStream(fullDirectory);
                InputStream in = zipFile.getInputStream(zipEntry);
                for (int c = in.read(); c != -1; c = in.read()) {
                    fout.write(c);
                }
                zipFile.getInputStream(zipEntry).close();
                in.close();
                fout.close();
            }
        }
        zipFile.close();
        System.out.println("Unzipping complete!");

        zip.delete();

    } catch (IOException e) {
        System.out.println("Unzip failed");
        e.printStackTrace();
    }
}
  • 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-25T06:33:01+00:00Added an answer on May 25, 2026 at 6:33 am

    You’re copying the file one byte at a time

    for (int c = in.read(); c != -1; c = in.read())
        fout.write(c);
    }
    

    You could try using Apaches org.apache.commons.io.IOUtils.copy() as this’ll copy in chunks and use NIO and other improvements. You can find it in the commons-io.jar

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

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.