package com.compress; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.DataInputStream; 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 CompressEncodingTest { /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { File f = new File("中文测试.txt"); ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream( new FileOutputStream("zipTest.zip"), 1024)); zos.putNextEntry(new ZipEntry("中国人.txt")); DataInputStream dis = new DataInputStream(new BufferedInputStream( new FileInputStream(f))); zos.putNextEntry(new ZipEntry(f.getName())); int c; while ((c = dis.read()) != -1) { zos.write(c); } zos.setEncoding("gbk"); zos.setComment("中文测试"); zos.closeEntry(); zos.close(); } }
更多java知识请关注java基础教程栏目。
以上就是java压缩文件乱码问题的详细内容,更多请关注其它相关文章!