I have a method that adds an inputStream to a zip as a record:
private void addToZip(InputStream is, String filename) throws Exception { try { ZipEntry zipEntry = new ZipEntry(filename); zos.putNextEntry(zipEntry); byte[] bytes = new byte[1024]; int length; while ((length = is.read(bytes)) >= 0) { zos.write(bytes, 0, length); } zos.closeEntry(); } finally { IOUtils.closeQuietly(is); } }
The problem occurs when the file name contains UTF-8 char as áé ... In the zip file it will be saved as ????? , and when I unzip it in ubuntu 12.10, it looks like this: N├stroje instead of Nástroje .
In this example, I used jdk6, but now I also tried jdk7:
zos = new ZipOutputStream(fos, Charset.forName("UTF-8"));
But without success.
I also tried Apache Commons Zip and set the encoding, but also did not succeed.
So, how can I add this file with Unicode characters in the file name for zip?
hudi
source share