hi all, anyone has another example of unzip with source codes to demo here? This set of unzip codes don't work. Thanks!
import java.io.*;
import java.util.*;
import java.util.zip.*;
public class Unzip {
public static final void copyInputStream(InputStream in, OutputStream out)
throws IOException
{
byte[] buffer = new byte[1024];
int len;
while((len = in.read(buffer)) >= 0)
out.write(buffer, 0, len);
in.close();
out.close();
}
public static final void main(String[] args) {
Enumeration entries;
ZipFile zipFile;
try {
zipFile = new ZipFile("C:\\Temp
FolderZiper.zip");
entries = zipFile.entries();
while(entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry)entries.nextElement();
if(entry.isDirectory()) {
// Assume directories are stored parents first then children.
System.err.println("Extracting directory: " + entry.getName());
// This is not robust, just for demonstration purposes.
(new File(entry.getName())).mkdir();
continue;
}
System.err.println("Extracting file: " + entry.getName());
copyInputStream(zipFile.getInputStream(entry),
new BufferedOutputStream(new FileOutputStream(entry.getName())));
}
zipFile.close();
} catch (IOException ioe) {
System.err.println("Unhandled exception:");
ioe.printStackTrace();
return;
}
}
}
-
An example of unzip (1 messages)
- Posted by: Vivian Richardson
- Posted on: August 11 2005 00:00 EDT
Threaded Messages (1)
- If it is a compressed archive... by Sowmya Sridhar on August 15 2005 10:02 EDT
-
If it is a compressed archive...[ Go to top ]
- Posted by: Sowmya Sridhar
- Posted on: August 15 2005 10:02 EDT
- in response to Vivian Richardson
This code does not work if u use a compressed archive. If you had control on how the jar file is built, then u could make a jar without compression and this program will work just fine!