This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to extract subdirectories with Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to extract subdirectories with" Watch "How to extract subdirectories with" New topic

How to extract subdirectories with

Robert Jaeger
Ranch Hand

Joined: Apr 29, 2002
Posts: 62

I�m using the package to extract zip-files.
I found a lot of documentation and descriptions ... the extraction works.
Unfortunately this is only the case for files in the main directory of the zip-file, subdirectories cannot be extracted ...
... or maybe someone has an idea, that would be great

satish sathineni
Ranch Hand

Joined: May 03, 2004
Posts: 46
I think this code should solve ur problem...

import java.util.Enumeration;

* -----------------------------------------------------------------------------
* Used to provide an example of extracting the contents (files) from a zip
* file.
* -----------------------------------------------------------------------------

public class UnzipFile {

private static void doUnzipFiles(String zipFileName) {

try {

ZipFile zf = new ZipFile(zipFileName);

System.out.println("Archive: " + zipFileName);

// Enumerate each entry
for (Enumeration entries = zf.entries(); entries.hasMoreElements() {

// Get the entry and its name
ZipEntry zipEntry = (ZipEntry)entries.nextElement();
String zipEntryName = zipEntry.getName();
System.out.println(" inflating: " + zipEntryName);

OutputStream out = new FileOutputStream(zipEntryName);
InputStream in = zf.getInputStream(zipEntry);

byte[] buf = new byte[1024];
int len;
while((len = > 0) {
out.write(buf, 0, len);

// Close streams

} catch (IOException e) {


* Sole entry point to the class and application.
* @param args Array of String arguments.
public static void main(String[] args) {

if (args.length != 1) {
System.err.println("Usage: java UnzipFile zipfilename");
} else {



Have Fun ....

I agree. Here's the link:
subject: How to extract subdirectories with
It's not a secret anymore!