• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to zip files and folders in a directory into 1 zip file?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have written a zip code which can zip files from a directory into 1 zip file. However, when it encounters a folder in that directory, it compresses the folder into a seperate zip file.

Below is the code:



The part where the folder is dealt with is under the "elseif fileArray[i].isDirectory()) ". Recursion is used to get into the folder to read the files inside for compression.

I have made the file and zip output streams to have the same location (destZipFile) so that the folder to be compressed can be placed in the same zip file. However, when I ran the program, there is no trace of the folder being zipped.

How do I manage to zip all files and folders inside a directory into 1 zip file?
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're creating a new ZipOutputStream every time you call the method. These two linesneed to be taken out and put before the first call to your method. Then pass zipOS to the method instead of destZipFile.
[ January 24, 2008: Message edited by: Joanne Neal ]
 
"To do good, you actually have to do something." -- Yvon Chouinard
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic