首页 > 代码库 > java.util.zip.ZipOutputStream压缩无乱码(原创)
java.util.zip.ZipOutputStream压缩无乱码(原创)
package io; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.zip.Adler32; import java.util.zip.CheckedOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class ZipCompress { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub String[] fileNames={"config.properties","中文.properties","中文.csv"}; FileOutputStream f=new FileOutputStream("test.zip"); CheckedOutputStream csum=new CheckedOutputStream(f, new Adler32()); ZipOutputStream zos=new ZipOutputStream(csum); BufferedOutputStream out=new BufferedOutputStream(zos); zos.setComment("comment"); for (String fileName : fileNames) { BufferedReader in=new BufferedReader(new InputStreamReader(new FileInputStream(fileName),"GBK")); zos.putNextEntry(new ZipEntry(fileName)); String temp; while((temp=in.readLine())!=null){ out.write(temp.getBytes("GBK")); } in.close(); out.flush(); } out.close(); } }
测试用到的文件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。