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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:49:34+00:00 2026-05-21T03:49:34+00:00

I am currently trying to zip all files within a directory. The zip file

  • 0

I am currently trying to zip all files within a directory.

The zip file is being created and the files are being processed – but for some reason the files are not appearing within the zip file.

The code being used to complete this task is as follows:

public class FileZipper {

   public void zipDir( String dir, String zipFileName ) {
        try{
            File dirObj = new File(dir);
            ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName));
            Logger.info("Creating : " + zipFileName);
            addDir(dirObj, out);
            out.close();
        }
        catch (Exception e){
            Logger.error( e, "Error zipping directory" );
        }
  }

  private void addDir(File dirObj, ZipOutputStream out) throws IOException {
      File[] files;
      if( !dirObj.isDirectory() ){
          files = new File[] { dirObj };
      }
      else{
          files = dirObj.listFiles();
      }
      byte[] tmpBuf = new byte[1024];

      for (int i = 0; i < files.length; i++) {
          if (files[i].isDirectory()) {
              addDir(files[i], out);
              continue;
          }
          FileInputStream in = new FileInputStream(files[i].getAbsolutePath());
          Logger.info(" Adding: " + files[i].getAbsolutePath());
          out.putNextEntry(new ZipEntry(files[i].getAbsolutePath()));
          int len;
          while ((len = in.read(tmpBuf)) > 0) {
              out.write(tmpBuf, 0, len);
          }
          out.closeEntry();
          in.close();
      }
  }
}

When reviewing the logging information, the files within the directories are being found and processed, but the created zip file contains no data.

Any help with this issues will be greatly appreciated.

Thanks

  • 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-21T03:49:35+00:00Added an answer on May 21, 2026 at 3:49 am

    Apart from the fact that adding the file by its absolute path is probably not what you want, this code works just fine for me.

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

Sidebar

Related Questions

In this situation, I have created a zip file containing search result files, and
I'm trying to Flush a Zip file that has just been created, and have
I am trying to write a tool to create a zip file containing all
Im currently trying to downlaod a audio track from a WCF, i need some
Im currently trying to learn some stuff about encryption, it's algorithms and how it
I am currently trying to write some code that will accept some FTP details,
I'm currently trying to set up a secured folder with a few pages within
I am trying to save (compress) a .zip file using JclCompression with the JCL
I am trying to get a file size of remote file compiler-latest.zip (googlecode.com) using
I am currently trying to validate some front-end values with some server-side methods (as

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.