Zip.ZipInputStream cannot extract files with Chinese chars in name

Dear friends,
Peace b upon u!
I am trying to read a zip file (~3000 files)containing one
or more files with Chinese, Japanese or Korean names, the
getNextEntry method throws an IllegalArgumentException as below after extracting just ~300 files as below:-
java.lang.IllegalArgumentException
        at java.util.zip.ZipInputStream.getUTF8String(Unknown Source)
        at java.util.zip.ZipInputStream.readLOC(Unknown Source)
        at java.util.zip.ZipInputStream.getNextEntry(Unknown Source)
        at testZipFiles.getZipFiles(testZipFiles.java:65)
        at testZipFiles.main(testZipFiles.java:18) issue:java.util.zip.ZipInputStream cannot extract files with Chinese chars in name
Category java:classes_util_jarzip
Plz let me know 1 of the ways which I can solve this issue.
1)if someone has JAVA DCOMPILER plz send the SOURCE Code
for the ZipInputStream.class to me..I need to edit it using 1 of the solutions as provided below which I googled.
2)If there is an alternate or upgraded java.util.zip.ZipInputStream or any org.apache.tools.zip.* package which can read such files..If yes where I can download the same on net.
3)Any other easier solution, which can let me extract all files (by excluding Chinese files thru CATCH) without the extractor process to fail altogether.
On net I found that the only solution with this is:-
- edit the new ZipEntry, remove the static initializer that calls
the native methods initIDs().
this step seems a bit scary, but it's according to the
workaround
to bug #4244499 (the workaround of Olive64, THU JUN 05
01:55 P.M. 2003),
that handles a similar bug at the ZipOutputStream.
Now you have a ZipInputStream that supports multi-bytes
entry names.
to extract the zip file, using the fixed code that is offered
above,
create a function that gets an "encoding" string, a "destPath"
string
and a "sourceFile" (zipped) and does :
ZipInputStream zipinputstream = null;
ZipEntry zipentry;
zipinputstream = new ZipInputStream(new FileInputStream
(sourceFile),encoding);
zipentry = zipinputstream.getNextEntry();
while (zipentry != null) { //for each entry to be extracted
    String entryName = zipentry.getName();
    int n;
    FileOutputStream fileoutputstream = new FileOutputStream
( destPath + entryName );
    while ((n = zipinputstream.read(buf, 0, 1024)) > -1)
        fileoutputstream.write(buf, 0, n);
    fileoutputstream.close();
    zipinputstream.closeEntry();
    zipentry = zipinputstream.getNextEntry();
}//while
zipinputstream.close();

Hi friend,
We'd better to ask one question in each thread. If you have another issue, you can consider to open up a new thread in this forum.
Now for the first question, do you mean this picture? It throws access exception in archive2.
If so , because your extractPath is a path, not a directory.You should add +"xxx.zip". For more information, please refer to
ZipFile.Open
Method (String, ZipArchiveMode).
For the second question, you can use the following code to skip the error message.
while (true)
try
//do something;
catch (Exception ex)
{ continue; }
Good day!
Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • Web.show_document cannot display file with Chinese char in IIS 6

    Dear all,
    There is a problem that web.show_document cannot display file with Chinese char in IIS 6, but works fine in IIS 5.
    Is it a server problem or is there any setting in server? Do you know how to solve it?
    Big Thanks
    JY

    Hi,
    As Francois mentioned, this issue has nothing to do with forms / web.show_document. web.show_document, just opens the URL specified as parameter. So, if you run the URL (that you've passed as argument for web.show_document), directly in the browser, you would be getting the same issue.
    So, as you said, if it works fine in IIS 5 and does not in IIS 6, it would be an issue with the IIS and not forms. You might want to check out the IIS 6 release notes / documentation for any known issues / raise an issue in that.
    -Arun

  • Problem with zipping file with chinese chars

    I need to zip a html page which contains some chinese characters, I am able to zip it and create a zip file
    but the problem is when i open the zip file and view the html file it displays junk characters instead
    of chinese characters
    Here is what i am doing
      ByteArrayOutputStream bStream = new ByteArrayOutputStream();
       ZipOutputStream zStream = new ZipOutputStream(bStream);
        ZipEntry zipEntry = new ZipEntry(htmlFilename);
        zStream.putNextEntry(zipEntry);
        ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
        PrintWriter writer = new PrintWriter(
                               new OutputStreamWriter(dataStream,"UTF-8"));
    writer.write(htmlString); //htmlString is the string which contents the html contents which has chinese char
        writer.close();
    zStream.write(dataStream..toByteArray());

    And when you view the unzipped file, are you using something that realizes that you encoded your data using UTF-8? My guess is that you are not.
    PC²

  • How can I see file with chinese name in Sunray USB storage?

    hi, All
    I installed Sunray4u3 on Solaris0805. the application server is win2003EE.
    I accessed usb storage from win2003, but I can only see files with English name , and could not see files with chinese name. Why? who can help?
    best regards
    xiong wei

    You might want to make sure your credit card is listed in the billing information associated with your Apple ID (see http://support.apple.com/kb/ht1918).
    Also, to change the From name that appears when you address emails on and iOS device, go to Settings>Mail,Contacts,Calendars...tap your iCloud email account, tap you iCloud account at the top, tap Mail at the bottom, then enter the name you want to use in the Name field at the top.
    To change the From name on your Mac Mail, go to icloud.com, sign into your account, open Mail, click the gear shaped icon on the bottom left and choose Preferences, go to the Accounts tab and enter the name you want to use in the Full Name field and click Done.  Then quit Mail on your Mac and re-open it.  Your new From name should now appear in the drop-down list when you compose a new email.

  • Importing CD to Artist folder\Album folder\file with track number and name:

    I have a problem then importing my cd’s to my harddisk using iTunes.
    On my previous pc I got what I want, Artist folder, Album folder and file with track number and name:
    e.g.
    D:\My Music\B.B. King\Blues On The Bayou\01 Blues Boys Tune.mp3
    D:\My Music\B.B. King\Blues On The Bayou\02 Bad Case Of Love.mp3
    D:\My Music\B.B. King\Blues On The Bayou\03 I'll Survive.mp3
    But now I get:
    D:\My Music\Compilations\Blues On The Bayou\01 Blues Boys Tune.mp3
    D:\My Music\ Compilations \02 Bad Case Of Love.mp3
    D:\My Music\ Compilations \03 I'll Survive.mp3
    In iTunes my settings are Edit -> Preferences -> Advanced: iTunes Music folder: D:\My Music and checkmark in both: “Keep iTunes Music folder organized” and “Copy files to iTunes Music folder when adding to library”.
    My version of iTunes is 8.0.1.11
    Thanks in advance
    Peter

    It will depend on the album. Gracenote considers anthologies, a collection of tracks by the same artist taken from different albums, as a compilation. In iTunes the compliation setting should really only be applied to a collection of tracks by different artists.
    tt2

  • Zip file with special chars are not unzipped properly

    Hi all,
    i have following problem: I want to unzip a zip file. In the zip file there is a file with a special character i.e. "straße". When i call now zipFile.getInputStream( entry ) null will be returned. What can i do? Thanks a lot
    ZipFile zipFile = new ZipFile( file );
        Enumeration enumeration = zipFile.entries();
        while ( enumeration.hasMoreElements() )
          ZipEntry entry = ( ZipEntry ) enumeration.nextElement();
          if ( !entry.isDirectory() )
            InputStream in = null;
            OutputStream out = null;
            try
              in = zipFile.getInputStream( entry );  //<- Here null will be returned When i look at the entry the "ß" of "straße" is represented by á.

    May be you need to specify an ecoding for ZipEntry that would allow special characters?

  • Having problems creating a zip file with Japanese language character names

    I have a bunch of files with names in Japanese characters (also Chinese, Korean, Spanish etc, but this will do for an example). The encoding is Unicode.
    I wish to be able to put them in a zip file, then extract them again using any old zip tool (WinZip,PKZip,7-Zip etc)
    Trouble is, every time I do it, the files inside the zipfile end up with garbage character names. The contents of the files are fine, though.
    I'm aware that there used to be a bug in the java.util.zip.* classes regarding character encodings (http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=5bd4fe01ad8a7b4ec89afef5005da?bug_id=4244499) but as far as I can see it's supposed to have been fixed I have also tried the ZipOutputStream class from apache which allows you to set the encoding manually - no luck there either (just many different varieties of garbage characters)
    Test code below. What am I missing here?
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.IOException;
    public class ZipTest {
    static String uniqueFileName = "&#35199;&#12288;&#32020;.txt";
    public static void main(String[] args) {
    try {
    standardZip();
    apacheZip();
    } catch (IOException fe) {
    System.out.println("problem in file - exception " + fe.getMessage());
    public static void apacheZip() throws IOException {
    String encoding = "";
    File inputFile = new File(uniqueFileName);
    FileReader reader = new FileReader(inputFile);
    encoding = reader.getEncoding();
    System.out.println("Using Apache - Encoding = " + encoding);
    File zipFile = new File("apacheZip.zip");
    org.apache.tools.zip.ZipOutputStream zipOutputStream = new org.apache.tools.zip.ZipOutputStream(
    zipFile);
    zipOutputStream.setEncoding(encoding);
    org.apache.tools.zip.ZipEntry zipEntry = new org.apache.tools.zip.ZipEntry(uniqueFileName);
    zipEntry.setSize(inputFile.length());
    zipEntry.setTime(inputFile.lastModified());
    zipOutputStream.putNextEntry(zipEntry);
    int c = 0;
    while (c >= 0) {
    c = reader.read();
    if (c >= 0) {
    zipOutputStream.write(c);
    zipOutputStream.closeEntry();
    zipOutputStream.finish();
    public static void standardZip() throws IOException {
    String encoding = "";
    File inputFile = new File(uniqueFileName);
    FileReader reader = new FileReader(inputFile);
    encoding = reader.getEncoding();
    System.out.println("Using Java IO - Encoding = " + encoding);
    File zipFile = new File("standardZip.zip");
    FileOutputStream zipOut = new FileOutputStream(zipFile);
    java.util.zip.ZipOutputStream zipOutputStream = new java.util.zip.ZipOutputStream(zipOut);
    java.util.zip.ZipEntry zipEntry = new java.util.zip.ZipEntry(uniqueFileName);
    zipEntry.setSize(inputFile.length());
    zipEntry.setTime(inputFile.lastModified());
    zipOutputStream.putNextEntry(zipEntry);
    int c = 0;
    while (c >= 0) {
    c = reader.read();
    if (c >= 0) {
    zipOutputStream.write(c);
    zipOutputStream.closeEntry();
    zipOutputStream.finish();

    Emma_Baillie wrote:
    I have a bunch of files with names in Japanese characters (also Chinese, Korean, Spanish etc, but this will do for an example). The encoding is Unicode.
    I wish to be able to put them in a zip file, then extract them again using any old zip tool (WinZip,PKZip,7-Zip etc)
    Trouble is, every time I do it, the files inside the zipfile end up with garbage character names. The contents of the files are fine, though.This is becuase zip tool doesn't support unicode for zip entries. For example WinZip prior to 11.2 does not support Unicode characters in filenames. You need to look for the simillar information for other tools. You can find more on tools on their website.

  • Cannot extract files

    Hi ive been looking on this website for help trying to extract files on my mac and i've come across answers like downloading stuffit or unarchiever and these are both not working.
    When i download a file usually ending with .exe my mac says it cannot extract this file then even on unarchiever i have every type of file selected for it to open it says that the contents of my file cannot be extracted with this program what is going on can anyone help me

    As cheonweb says they are Windows only.
    Why are you downloading .exe files, are you downloading Applications that you want to use on the Mac? If you are and you are a new Mac user, I suggest you check out Apples App store, all those should work with your Mac. Occasionally you need to run a Windows only application but that is a different problem and solution.

  • Serving up files with Russian chars in the file name

    Anyone know how to get CF 8 to serve up CFM files with
    Russian characters in the file name? I can get IIS to server up
    .html files but .cfm files turn in to ?????????.cfm files.
    For example, this:
    новостииобновления.cfm
    becomes this ??????????????.cfm and throws a CF error (File Not
    Found) when clicking on the link. The strange thing is I can see
    the Russian characters in the status bar when I mouse over the link
    but CF can't handle it. And IIS will serve up the file and replace
    all the chars with their URL entity equivalent.
    Any suggestions on how to fix?

    Open the Script Editor or AppleScript Editor in one of the subfolders of Applications and run the following:
    tell application "Finder" to quit
    if (do shell script "defaults read com.apple.finder AppleShowAllFiles") is "1" then
    do shell script "defaults write com.apple.finder AppleShowAllFiles 0"
    else
    do shell script "defaults write com.apple.finder AppleShowAllFiles 1"
    end if
    delay 2
    tell application "Finder" to run
    If you change your mind later, run the script again.
    (93787)

  • Help! Cannot open files with certain applications

    I updated to OS Tiger from OSX some weeks ago. Before, I could run a program that labels files in a given folder with names given in an Excel file (csv format). This "csv sorter" usually asks for the csv file once I put in the folder with the files that should be labeled. In the dialog window that opened I could just go through my harddrive to my csv file and choose it. Now the csv files always appear in pale grey and I cannot click on them. Has anybody an idea why certain programs should not recognize certain filetypes any more in OS Tiger? It seems like I cannot access any file with the csv sorter any more, no matter which file type. Thanks for your help!

    found this on another websites forum .... it worked
    I figured it out. Thanks everyone!
    I had to turn on my wireless mouse... And even though I wasn't using my wireless mouse and just the trackpad...I had to turn on my wireless mouse then adjust those settings...Had to turn down the speed. Then Once I shut the mouse off and started to use the trackpad again it works perfectly.
    I'm not sure why the mouse settings would change the trackpad settings but it did.

  • Flat file with chinese characters

    Hi all,
    I am working on a solution to map a file with this structure (not xml):
    //.comment 1
    0~keyh2..hn~
    0~it1it2..itn~key
    0~it1it2..itn~key
    //.comment 2
    0~keyh2..hn~
    0~it1it2..itn~key
    0~it1it2..itn~key
    0~it1it2..itn~key
    This is my conversion setup
    recordser.structure = comment,1,header,1,item,*
    recordset.sequence = variable
    keyFieldName = key
    comment.fieldSeparator = .
    comment.fieldStructure = key.comment
    comment.keyFieldValue = //
    header.fieldSeparator = ~~
    header.beginSeparator = 0~~
    header.endSeparator = ~~
    header.fieldStructure = 0~keyh2..hn~
    header.keyFieldValue = 0
    item.fieldSeparator = ~~
    item.beginSeparator = 0~~
    item.fieldStructure = 0~it1it2..itn~key
    item.keyFieldValue = 1
    The problem now is that this file come from Chinese system and it is provide with chinese letters (looks like 2 bytes per letter). When I provide character encoding as ISO-2022 then adapter shows exception:
    java.io.UnsupportedEncodingException
    when I try to process it without passing any encoding then the exception is:
    more elements in file csv structure than field names specified
    Is there anyone who can help me with these?
    br
    Dawid

    Hi,
    I think it is something wrong with the File content conversion parameters parameters.
    You can avoid comment 1 and comment 2 by using the parameter Document offset.Follow this link for that:
    <a href="http://help.sap.com/saphelp_nw04/helpdata/en/2c/181077dd7d6b4ea6a8029b20bf7e55/content.htm">http://help.sap.com/saphelp_nw04/helpdata/en/2c/181077dd7d6b4ea6a8029b20bf7e55/content.htm</a>.
    I think you didn't specify the field names in the File Content Conversion parameters.
    Follow these two weblogs for the File Content Conversion parameters:
    <a href="/people/venkat.donela/blog/2005/06/08/how-to-send-a-flat-file-with-various-field-lengths-and-variable-substructures-to-xi-30:///people/venkat.donela/blog/2005/06/08/how-to-send-a-flat-file-with-various-field-lengths-and-variable-substructures-to-xi-30
    <a href="/people/michal.krawczyk2/blog/2004/12/15/how-to-send-a-flat-file-with-fixed-lengths-to-xi-30-using-a-central-file-adapter">/people/michal.krawczyk2/blog/2004/12/15/how-to-send-a-flat-file-with-fixed-lengths-to-xi-30-using-a-central-file-adapter</a>
    Hope it helps.
    Regards,
    JE

  • Cannot open files with a double click !! Trackpad solution does not work, just makes my cursor move slowly. Have not found a solution in forums. Help needed please!!

    I cannot open files by double clicking ... have looked at forums and no solution yet !!! Control click is the only way i can open files
    "If you go to System Preferences > Accessibility > Mouse and Trackpad -  You can set the speed of the double click to be much slower.   Hope this helps someone else with a similar problem. "  this solution did not work it just made my cursor move at a snails pace.
    Thanks for any help forthcoming !!!

    found this on another websites forum .... it worked
    I figured it out. Thanks everyone!
    I had to turn on my wireless mouse... And even though I wasn't using my wireless mouse and just the trackpad...I had to turn on my wireless mouse then adjust those settings...Had to turn down the speed. Then Once I shut the mouse off and started to use the trackpad again it works perfectly.
    I'm not sure why the mouse settings would change the trackpad settings but it did.

  • Firefox 3 cannot download files with white space in the filename

    When opening attachments in e-mail Firefox is unable to handle files with white space in the name. This is not the same as the white space file name truncation problem documented on this site (where file names with white space are truncated on saving.) The issue is that the browser will prompt to allow the file to be saved, but it will not prompt to open the file as an option. If I rename the file to remove white space then I do receive the "Open with..." dialog box. I verified that Firefox 2 did not have this problem and I can open attachments with white space in the file names just fine using that version of the browser (2.0.0.20).
    == This happened ==
    Every time Firefox opened
    == Upgraded to version 3

    When a user clicks on an attachment with spaces, the filename is truncated to the first whitespace. While IE, Chrome & Safari handle this, Firefox refuses to accept mime headers with unquoted filename parameters. According to Firefox's bugzilla/knowledgebase, Firefox's behavior is the correct behavior and it's a problem with most webservers or web applications. This problem can be easily corrected by surrounding the filename parameter with double quotes.
    Eg.
    Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

  • Cannot copy file with other buffer sizes, except 1

    Hi,
    i'd like to copy files (txt, images, etc) , but by using the following route:
    -read bytes from a file in a ByteBuffer
    -use a byte array to create a String representation in binary form (ie "0101101") of the ByteBuffer
    -print the string
    and then the reverse:
    -create a byte array from the String
    -put the bytes in another ByteBuffer
    -write them to the destination file
    The problem is, that in the general case, this only works for ByteBuffer.allocate(1)! it works for txt files with any size, but not for image files; i have not tried for any other kind of file.
    Ideas?
    import java.io.*;
    import java.nio.*;
    import java.nio.channels.*;
    import java.math.*;
    /* create the copy of a file:
    * In the middle print a string with the contents of the buffer, in binary form
    * and then use this string to create the copy of the picture.
    public class CopyFile
      static public void main( String args[] ) throws Exception
         if (args.length<2) {
          System.err.println( "Usage: java CopyFile infile outfile" );
          System.exit( 1 );
        String infile = args[0];
        String outfile = args[1];    
        FileInputStream fin = new FileInputStream( infile );
        FileOutputStream fout = new FileOutputStream( outfile );
        FileChannel fcin = fin.getChannel();
        FileChannel fcout = fout.getChannel();
        ByteBuffer bufferSource = ByteBuffer.allocate( 1 );
        ByteBuffer bufferDest = ByteBuffer.allocate( 1 );
        byte[] barraySource;
        byte[] barrayDest;
        while (true) {
          bufferSource.clear();
          int r = fcin.read( bufferSource );
          barraySource=bufferSource.array();
          BigInteger biFrom = new BigInteger(barraySource);           
          String binary = biFrom.toString(2);
          System.out.println(binary+" | ");     
           BigInteger biTo=new BigInteger(binary,2);
           barrayDest=biTo.toByteArray();
           bufferDest.clear();
           bufferDest.put(barrayDest);
          if (r==-1) {
            break;
          bufferDest.flip();
          fcout.write(bufferDest);
    }

    I've changed a couple of things, but the problem remains. It is the first time i work with binary data. Can somebody give me a hint?
    public class Test2
        public static void main(String[] args) throws Exception
            File fin=new File("C:\\Documents and Settings\\p3020139\\My Documents\\pic.JPG");
            File fout=new File("C:\\Documents and Settings\\p3020139\\My Documents\\piccp.JPG");
            FileInputStream fis=new FileInputStream(fin);
            FileOutputStream fos=new FileOutputStream(fout);       
            long fileSize= fin.length();
            long bytesRead=0;
            BufferedOutputStream baos=null;
            while (bytesRead<fileSize+1)
                byte[] barray=new byte[128];
                int read=fis.read(barray); 
                BigInteger biFrom = new BigInteger(barray);           
                String binary = biFrom.toString(2);
                System.out.println(binary);
                BigInteger biTo=new BigInteger(binary,2);
                byte[] bytesTo=biTo.toByteArray();
                baos=new BufferedOutputStream(fos,128);
                baos.write(bytesTo);
                bytesRead=bytesRead+read;
            fis.close();
            baos.close();
        }

  • Cannot open file with GRD file extension

    I received a file with a GRD file extension, but get an error message saying the gradient file is bad or corrupted. I tried 3 separate files, same result.
    According to the internet, Photoshoop is supposed to be able to open these files.
    Does Photoshop open GRD files, is there a patch I need, or is there another program better suited to open these files?
    Thanks,
    Al

    What app did you create the .grd file with?
    Can you provide a link to a file that's giving you trouble, so others can try to open it?
    -Noel

Maybe you are looking for