Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: ZipInputStream Throws Illegalargument exception for diacritics

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default ZipInputStream Throws Illegalargument exception for diacritics

    Hi,


    If I run the below program with the zip file which has some files with diacritic characters (e.g 1-2GF-969##JÖN.pdf) , I get IllegalArgumentException.

    My application has to support all languages. So, we set encoding to UTF-8


    All languages work fine. But the problem comes when reading diacritic characters.

    I tried using alternatives to zip input stream, like arcmexer, but it does not support Chinese characters.

    Please help me with this.

    private static void readUsingJava() {
    ZipInputStream zis;
    try {
    zis = new ZipInputStream(new FileInputStream("C:\\Check.zip"));
    ZipEntry ze;
    while ((ze = zis.getNextEntry()) != null) {
    System.out.println("Name of the File Is :: " + ze.getName());
    }
    zis.close();
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: ZipInputStream Throws Illegalargument exception for diacritics

    The bad news is that this is a known bug which seems to have been around forever, and any workarounds suggested are absurd.

    The good news is that the bug is announced as fixed in Java 1.7(b57)
    Bug ID: 5030283 Incorrect implementation of UTF-8 in zip package
    Bug ID: 4820807 java.util.zip.ZipInputStream cannot extract files with Chinese chars in name
    Bug ID: 4244499 ZipEntry() does not convert filenames from Unicode to platform

    More on getUTF8String zipinputstream site:bugs.sun.com - Google Search

    db

  3. #3
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: ZipInputStream Throws Illegalargument exception for diacritics


  4. #4
    Junior Member
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: ZipInputStream Throws Illegalargument exception for diacritics

    Thanks a lot sir.
    We are using web logic 9 and it does not have support for JDK7 .

    i tried apache commons compress. It works fine for diacritics but it does not support chinese chars. :-)

    Here we can specify encoding format.

    This fails for chinese characters. Does not throw exception, but the characters are not displayed correctly.

    ZipArchiveInputStream zin = new ZipArchiveInputStream(name, "UTF-8", true);
    org.apache.commons.compress.archivers.zip.ZipArchi veEntry entry = null;
    log.debug("Inside getTotalNoOfFilesinZip");
    while((entry = zin.getNextZipEntry()) != null)
    {
    entry.getName() //Obtain name of the file
    }
    Last edited by meghaladevi; October 7th, 2010 at 05:43 AM.

  5. #5
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

  6. #6
    Junior Member
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: ZipInputStream Throws Illegalargument exception for diacritics

    Hi Darryl,

    Thanks a lot for your help.
    This works fine with Apache commons compress and Winzip - latest version - 14.5.
    I tried with evaluation version of WinZIP.


    We have got license for Winzip 9 only. It does not work with Winzip 9 and apache :-)
    So, I'm trying to find some alternative solutions. If you know, kindly help.

Similar Threads

  1. [SOLVED] File.createTempFile() throws exception on Win7
    By jitinsingla in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 10th, 2010, 02:14 PM
  2. Exception during xml validation
    By vijeta in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 6th, 2010, 02:50 AM
  3. Reserved word "throws"
    By Lil_Aziz1 in forum Exceptions
    Replies: 1
    Last Post: January 1st, 2010, 01:12 AM
  4. Exception Errors
    By TIMBERings in forum Exceptions
    Replies: 1
    Last Post: December 10th, 2009, 02:13 AM
  5. Exception handling
    By AnithaBabu1 in forum Exceptions
    Replies: 6
    Last Post: August 27th, 2008, 09:37 AM

Tags for this Thread