wood burning stoves 2.0
The moose likes I/O and Streams and the fly likes Problme with unzipping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Problme with unzipping " Watch "Problme with unzipping " New topic

Problme with unzipping

Geetha Desh

Joined: Dec 14, 2005
Posts: 3

I m writing code to list and extract all the files when a directory name is passed as an argument.
my code works fine if the directory contains all the zip files.it extracts all the files.

the problem i m getting when a directory contains subdirectory .it is giving me exception..
the code works fine if: it extratct all the files
geetha--directory name

the code doesnt work when
geetha---root directory
|_geetha1-sub directory
|__geetha2-subdirectory under geetha1 directory
|____ a2.zip
The code is as follows:

public static void Unzip(File fin,File fout)
try {
//File dir = new File(args[0]);
File[] children = fin.listFiles();
int length =children.length;
for (int i=0; i<length; i++) {
File f = children[i];
System.out.println("the File name is "+f.getName());
{System.out.println("Zip file found "+f.getName());
catch(Exception e)
{ System.out.println("Exception"+e); }//catch

public static void Unzipme(File fname,File fout) {
try {
BufferedOutputStream dest = null;
BufferedInputStream is = null;
ZipEntry entry;
ZipFile zipfile = new ZipFile(fname);
Enumeration e = zipfile.entries();
while(e.hasMoreElements()) {
entry = (ZipEntry) e.nextElement();
System.out.println("Extracting: " +entry);
is = new BufferedInputStream(zipfile.getInputStream(entry));
int count;
byte data[] = new byte[BUFFER];
File output_file = new File (fout,entry.getName ());
FileOutputStream fos = new FileOutputStream(output_file);
dest = new BufferedOutputStream(fos, BUFFER);
while ((count = is.read(data, 0, BUFFER)) != -1) {
dest.write(data, 0, count); }
catch(Exception e) {

any suggestions?
Thanks in advance
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199


Welcome to JavaRanch!

Do you know this guy? Seems like you're working on the same program.

So what is the exception you're seeing? With a quick glance at the code, I don't see the problem.

[Jess in Action][AskingGoodQuestions]
Geetha Desh

Joined: Dec 14, 2005
Posts: 3

i m getting filenot found exception..
Geetha Desh

Joined: Dec 14, 2005
Posts: 3

i m getting this exception

Extracting: F:\anand photos/sonu.JPG
java.io.FileNotFoundException: F:\F:\anand photos\sonu.JPG (The filename, direct
ory name, or volume label syntax is incorrect)
Thanks and Regards
payal agrawal
Ranch Hand

Joined: Oct 11, 2005
Posts: 44
Look at the URL below:

How to extract file/files from a zip file
I agree. Here's the link: http://aspose.com/file-tools
subject: Problme with unzipping
It's not a secret anymore!