Java – “illegalargumentexception: unmappable [1]” and compress the file with Greek characters

I want to use zipoutputstream to compress a file on windows (7) The problem is that the file name (and file content) also contains Greek characters(“ ГП 0000660040140521_ a. Txt ", gamma and PI) The code of the compressed file I use:

ZipOutputStream zipOs = new ZipOutputStream(
    new FileOutputStream("c:\\temp\\test.zip"),Charset.forName("cp737")
);

File sourceFile = new File("C:/Path/To/File/ГП0000660040140521_b.txt");
String entryName = sourceFile.getName().replaceAll("\\\\","/");
ZipEntry entry = new ZipEntry(entryName);
zipOs.putNextEntry(entry);
...
...

But on the last line (putnextentry call), I get an illegalargumentexception:

java.lang.IllegalArgumentException: UNMAPPABLE[1]
at java.util.zip.ZipCoder.getBytes(ZipCoder.java:95)
at java.util.zip.ZipOutputStream.writeLOC(ZipOutputStream.java:407)
at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:221)

I think there must be something wrong with the character mapping between Greek and UTF-8... What is the correct way to compress files with Greek characters in file names?

edit

If I use "UTF-8" as the character set, I can create a zip file, but the name of the compressed file is wrong:“ ð ô ð ƒ0000660040140521_ a. Txt "(Greek characters missing)

Solution

I wrote this (late) answer because of my question "miso" and "kriegax" comments

If I remember reading the utf8 folder anywhere, the support in the zip file is a big weakness of the zip file (because UTF-8 is not the official zip standard support? Now you can use the existing zip applications, which support UTF-8 in the file name

However In our case, we can replace the Greek characters with "normal" characters ("a... Z"), because the compressed file is generated by the financial printer and contains one Greek character in each case: a "Pi" (only one solution...)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>