Our product has an export function that uses ZipOutputStream for the zip directory; however, when you try to pin a directory containing file names with a Chinese or Japanese character, the export does not work properly. For some reason, new files in a zipped file are named differently. Here is an example of our code:
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName)); out.setEncoding("UTF-8");
My import algorithm, also built into Java, can import the archived file correctly even if it contains Chinese / Japanese characters in the file / directory names.
Zipfile zipfile = new ZipFile(zipPath, "UTF-8"); Enumeration e = zipFile.getEntries(); while (e.hasMoreElements()) { entry = (ZipEntry) e.nextElement(); String name = entry.getName(); ....
Does the zip program have problems unpacking UTF-8 encoded files or is there something special that is needed to create a zip file that can be easily used by existing software using utf-8 encoding?
I wrote an example program:
package ZipFile; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import org.apache.tools.zip.ZipEntry; import org.apache.tools.zip.ZipOutputStream; public class ZipFolder{ public static void main(String[] a) throws Exception { String srcFolder = "D:/9.4_work/openscript_repo/δΈζ124.All/δΈζ"; String destZipFile = "D:/Eclipse_Projects/OpenScriptDebuggingProject/src/ZipFile/demo.zip"; zipFolder(srcFolder, destZipFile); } static public void zipFolder(String srcFolder, String destZipFile) throws Exception { ZipOutputStream zip = null; FileOutputStream fileWriter = null; fileWriter = new FileOutputStream(destZipFile); zip = new ZipOutputStream(fileWriter); zip.setEncoding("UTF-8");
}
source share