Zip圧縮 -part3 日本語文字化け-
エントリー名を日本語にすると文字化けする。エンコードを変えれば可能かと思ったが、UTF8、ISO8859-1、ISO2202-JPを試したがだめだった。どうすりゃいいんだ?
import java.util.*; import java.util.zip.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { byte[] buf = new byte[1024*1024]; ZipOutputStream zip = new ZipOutputStream(new FileOutputStream("hoge.zip")); zip.putNextEntry(new ZipEntry(new String("あいうえお.txt".getBytes(), "Shift_JIS"))); FileInputStream in = new FileInputStream("あいうえお.txt"); int size = in.read(buf); in.close(); zip.write(buf, 0, size); zip.closeEntry(); zip.close(); ZipFile zfile = new ZipFile("hoge.zip"); Enumeration e = zfile.entries(); while(e.hasMoreElements()) { ZipEntry entry = (ZipEntry) e.nextElement(); System.out.println(entry.getName()); for(byte b: entry.getName().getBytes()) System.out.println(b); } zfile.close(); } }