Problme with unzipping
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
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
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi
i m getting filenot found exception..
i m getting filenot found exception..
Geetha Desh
Greenhorn
Posts: 3
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Look at the URL below:
How to extract file/files from a zip file
http://www.java-tips.org/content/view/600/2/
How to extract file/files from a zip file
http://www.java-tips.org/content/view/600/2/
| Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |











