ZipInputStream 引发变音符号非法异常
如果我使用 zip 文件运行下面的程序,其中包含一些带有变音符号的文件(例如 1-2GF-969##JÖN.pdf),我会得到 IllegalArgumentException。
我的应用程序必须支持所有语言。因此,我们将编码设置为 UTF-8
所有语言都可以正常工作。但在阅读变音符号时就会出现问题。
我尝试使用 zip 输入流的替代品,例如 arcmexer,但它不支持中文字符。
请帮我解决这个问题。
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();
}
}
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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试使用的 ZIP 存档很可能不使用 UTF-8 编码。本文应该有所帮助:http://commons.apache.org/compress/zip.html
Most likely the ZIP archives you tried this with don't use UTF-8 encoding. This article should help: http://commons.apache.org/compress/zip.html