I am totally fresh in handling zip file using Java, and I have encountered a strange situation.
Here is the method I am using for unzip:
public void unzip(File zipFile, File rootDir) throws IOException
{
ZipFile zip = new ZipFile(zipFile);
Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zip.entries();
while(entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
java.io.File f = new java.io.File(rootDir, entry.getName());
if (entry.isDirectory()) { // if its a directory, create it
continue;
}
if (!f.exists()) {
f.getParentFile().mkdirs();
f.createNewFile();
}
/*BufferedInputStream bis = new BufferedInputStream(zip.getInputStream(entry)); // get the input stream
BufferedOutputStream bos = new BufferedOutputStream(new java.io.FileOutputStream(f));
while (bis.available() > 0) { // write contents of 'is' to 'fos'
bos.write(bis.read());
}
bos.close();
bis.close();*/
InputStream is = zip.getInputStream(entry);
OutputStream os = new java.io.FileOutputStream(f);
byte[] buf = new byte[4096];
int r ;
while ((r = is.read(buf)) != -1) {
os.write(buf, 0, r);
}
os.close();
is.close();
}
}
However, a IOException has been thrown and the message is:
INFO | jvm 1 | 2012/11/30 01:58:05 | java.util.zip.ZipException: error in opening zip file
INFO | jvm 1 | 2012/11/30 01:58:05 | at java.util.zip.ZipFile.open(Native Method)
INFO | jvm 1 | 2012/11/30 01:58:05 | at java.util.zip.ZipFile.(ZipFile.java:127)
INFO | jvm 1 | 2012/11/30 01:58:05 | at java.util.zip.ZipFile.(ZipFile.java:143)
Could anyone help me on this?
Thanks a lot.
Update:
I am using Linux as a testing environment. The permission for the unzip directory is drwxr-xr-x –
Update 02:
By adopting the suggestion from @heikkim,
I have just tried to use unzip commend in linux, trying to unzip my file manually. I have the following message:
Archive: TMA_Template.zip caution: zipfile comment truncated warning [TMA_Template.zip]: zipfile claims to be last disk of a multi-part archive; attempting to process anyway, assuming all parts have been concatenated together in order. Expect "errors" and warnings...true multi-part support doesn't exist yet (coming soon). error [TMA_Template.zip]: missing 6366880279 bytes in zipfile (attempting to process anyway) error [TMA_Template.zip]: attempt to seek before beginning of zipfile (please check that you have transferred or created the zipfile in the appropriate BINARY mode and that you have compiled UnZip properly)