Java cannot handle zip packages with special character file names

Source: Internet
Author: User

Http://bugs.sun.com/bugdatabase/view_bug.do? Bug_id = 4415733
Http://bugs.sun.com/bugdatabase/view_bug.do? Bug_id = 4244499

A long-history bug, but sun does not seem to be eager to modify it. But we have to rely on java.
Fortunately, there are more people who are happy to contribute. Fortunately, we also have a lot of open source.

Truezip can help us solve this problem, the URL is https://truezip.dev.java.net/

The following is a piece of code for testing:
[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 is a French project, the file name contains special characters in French, so use ISO-8859-1
Zipfile = new zipfile ("D:/temp/isl_2_02.zip", "ISO-8859-1 ");

Enumeration enum_entry = zipfile. Entries ();

// Remove the Regexp of the folder path in zipentry. For example, 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 FCM = 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 = FS. Read (B ))! =-1 ){
FOS. Write (B, 0, read );
}

FOS. Close ();
FCM. Close ();
}
}
}
[Code]
Another thing to note is that the import of classes uses drop-in replacements, so the classes such as file actually use de. schlichtherle. classes in the I/O package, instead of Java. class under Io.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.