This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets 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 ....

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: How to extract subdirectories with
Similar Threads
Help in encryption and decryption of file
zip file bug?
Can anyone help?
java API to extract ZIP, RAR and TAR files
How to password protect a zip file?