http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4415733
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4244499
A long-standing bug, but Sun doesn't seem to be in a hurry to change it, but it's hard for us to eat in Java.
Fortunately there are more people willing to give, but fortunately we also have a lot of open source.
Truezip just can help us solve this problem, the URL is https://truezip.dev.java.net/
Here's a piece of code I used to test:
[CODE]
Import De.schlichtherle.io.File;
Import De.schlichtherle.io.FileOutputStream;
Import De.schlichtherle.util.zip.ZipFile;
Import De.schlichtherle.util.zip.ZipEntry;
Import java.io.*;
Import java.util.Enumeration;
Import Junit.framework.TestCase;
public class Ziptest extends TestCase {
public void Testtruezip () throws Exception {
Because it's a French project, there are special French characters in the filename, so use iso-8859-1
ZipFile zipfile = new ZipFile ("D:/temp/isl_2_02.zip", "iso-8859-1");
Enumeration enum_entry = Zipfile.entries ();
The regexp that is used to remove the folder path in ZipEntry. Like Foler/file.txt => file.txt.
String pattern = "^ ([//s_//s]) * *";
int buffer_size = 1024 * 4;
while (Enum_entry.hasmoreelements ()) {
ZipEntry entry = (zipentry) enum_entry.nextelement ();
System.out.println ("d:/temp/ext/" + entry.getname (). ReplaceAll (Pattern, ""));
Bufferedinputstream fis = new Bufferedinputstream (Zipfile.getinputstream (entry));
FileOutputStream fos = new FileOutputStream (New File ("d:/temp/ext/" + entry.getname (). ReplaceAll (Pattern, ""));
Byte[] B = new Byte[buffer_size];
int read = 0;
while (read = Fis.read (b))!=-1) {
Fos.write (b, 0, read);
}
Fos.close ();
Fis.close ();
}
}
}
[CODE]
Another thing to note is that the introduction of the Class (import) takes the drop-in replacements, so the classes like file are actually used under the De.schlichtherle.io package, not the java.io below.