ZipEntry的文件名编码? [英] ZipEntry file name encoding?

查看:765
本文介绍了ZipEntry的文件名编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到在压缩文件的文件名的编码任何文件。

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

我要与德国变音符号的文件名打包成zip,其加载到Android和解压那里。然后,我要参考这些文件与存储在另一个文件名。后者是UTF-8,所以没有问题,变音符号。但我需要确保,即解压缩文件有正确的名称拆包对Android之后。

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 have the proper names after unpacking on the Android.

目前,我使用的Windows 7信息-ZIP打包存档,对Android的API函数来解压,和一切工作。不过,如果我使用了Java SDK JAR或7z格式的包装,文件出来在Android与错名字。这使我在想,如果在所有这方面的任何妥善的解决办法(除了使用古董ASCII文件名只)。

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).

我认为Android使用的Uni code文件名,所以我不得不做的是给力拉链程序连接code在统一code中的文件名了。这可能吗?

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?

感谢您的时间,RG

推荐答案

我找到了一个解决办法。

I found a workaround.

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

此功能转换的ISO-8859-1字符串到Java的Uni code字符串。你可以把这个给你从ZipEntry.getName()得到的文件名,并用它来存储文件。这使您可以生成拉链和阅读对Android的内容。

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.

有关从Windows(说)到Android运输,可以压缩使用的jar从JDK解压。信息-ZIP不起作用!

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

这是一个pretty很酷的解决方案,但它会失败的日文字符或任何东西了ISO-8859-1的。不知道该怎么办呢。

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.

这篇关于ZipEntry的文件名编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆