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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:42:04+00:00 2026-05-17T23:42:04+00:00

I am trying to zip the following file structure on my machine, parent/ parent/test1

  • 0

I am trying to zip the following file structure on my machine,

parent/
parent/test1
parent/test1/image1.jpeg
parent/test2

The problem here is i cant zip the above file structure using java. I have google and found following code sample but it only zip the files only inside a given folder.

     File inFolder=new File("out");
     File outFolder=new File("Out.zip");
     ZipOutputStream out = new ZipOutputStream(new 
BufferedOutputStream(new FileOutputStream(outFolder)));
     BufferedInputStream in = null;
     byte[] data    = new byte[1000];
     String files[] = inFolder.list();
     for (int i=0; i<files.length; i++)
      {
      in = new BufferedInputStream(new FileInputStream
(inFolder.getPath() + "/" + files[i]), 1000);                  
out.putNextEntry(new ZipEntry(files[i])); 
      int count;
      while((count = in.read(data,0,1000)) != -1)
      {
           out.write(data, 0, count);
          }
      out.closeEntry();
      }
      out.flush();
      out.close();

In the above code the out is a folder and we need to have some files..also folder cannot be empty if so it throws a exception java.util.zip.ZipException or cant contain any sub folders even files inside it (eg:out\newfolder\image.jpeg) if so it throws a java.io.FileNotFoundException: out\newfolder (Access is denied).

In my case im costructig the above file structure by quering the database sometime empty folders along the folder structure can be have.

Can some one please tell me a solution?

Thank You.

  • 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-17T23:42:05+00:00Added an answer on May 17, 2026 at 11:42 pm

    write two methods. The first one takes dirpath, makes a zip stream and calls another method which copies files to the zip stream and calls itself recursively for directories as below:

    1. open an entry in the zip stream for the given directory
    2. list files and dirs in the given directory, loop through them
    3. if an entry is a file, open an entry, copy file content to the entry, close it
    4. if an entry is a directory, call this method. Pass the zip stream
    5. close the entry.

    The first method closes the zip stream.

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

Sidebar

Related Questions

I am trying to download a zip file by using the following code; HttpConnection
I'm getting the following error when trying to deploy a ZIP file to a
I'm trying to use the following code to create a zip file from a
I have a zip file which contains the following directory structure: dir1\dir2\dir3a dir1\dir2\dir3b I'm
Im trying to make a file input field have the following extensions only .zip,
I have the following code for adding to/extracting from Zip. I'm trying to refactor
i'm trying to download .zip file from bluehost server to my computer. Like this
I was trying to read a self-extracting zip (located here ftp://ftp.dnr.state.oh.us/OilGas/Download/Production/By_Year/2010Production.exe ) using java
I'm trying to open a zip file with jython using FileInputStream and ZipInputStream. But
I am trying to create a zip file in PHP. The server environment is

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.