开发者

ZipEntry file name encoding?

I cannot find any documentation on the encoding of file names in zip files.

I have to pack file names with German umlauts into a zip, load it into an Android and unpack there. Then I have to refer to these files with names that are stored in another file. The latter is UTF-8, so there is no problem with umlauts. But I need to make sure, that the unzipped files 开发者_如何学Chave the proper names after unpacking on the Android.

Currently, I am using info-zip on Windows 7 to pack the archive, and the API functions on the Android to unpack, and everything worked. However, if I use jar from the Java SDK or 7z for the packaging, the files come out on the Android with wrong names. This makes me wonder, if there is any proper solution for this at all (besides using antique ASCII file names only).

I assume Android uses Unicode file names, so all I had to do is to force the zipper program to encode the file names in Unicode too. It this possible?

Thanks for your time, RG


I found a workaround.

public static String iso (String s)
    {
        byte bytes[]=EncodingUtils.getBytes(s,"iso-8859-1");
        return new String(bytes);
    }

This function converts an ISO-8859-1 string to a Java Unicode string. You can apply this to the filename you get from ZipEntry.getName(), and use it to store the file. This lets you generate zips and read the content on the Android.

For transportation from Windows (say) to Android, you can zip and unzip using jar from the JDK. Info-zip does not work!

That's a pretty cool solution, but it will fail for Japanese characters or anything out of ISO-8859-1. Don't know what to do then.


Last time I checked the SD card has a charset of ISO8859-1 and no UTF-8. This is for compatibility with Windows systems. I guess you will have to convert the Java Unicode strings to ISO8859-1. But I think the best solution would be to use ASCII-Characters only.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜