Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Problme with unzipping

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

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
|a1.zip
|a2.zip
========================

the code doesnt work when
===================
geetha---root directory
|_geetha1-sub directory
|__geetha2-subdirectory under geetha1 directory
|____a1.zip
|____ 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());
if(f.getName().endsWith(".zip"))
{System.out.println("Zip file found "+f.getName());
Unzipme(f,fout);
}
}//forloop
}//try
catch(Exception e)
{ System.out.println("Exception"+e); }//catch

}
public static void Unzipme(File fname,File fout) {
//System.out.println(fname);
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); }
dest.flush();
dest.close();
is.close();
}
}
catch(Exception e) {
e.printStackTrace();
}
}

any suggestions?
Thanks in advance
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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.
 
Geetha Desh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

i m getting filenot found exception..
 
Geetha Desh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.

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
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the URL below:

How to extract file/files from a zip file
http://www.java-tips.org/content/view/600/2/
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic