用ZIP进行简单文件压缩

public class GZIPcompress {
	public static void main(String[] args) throws IOException {
		FileOutputStream f =new FileOutputStream("D:\\test.zip");
		CheckedOutputStream csum =new CheckedOutputStream(f, new Adler32());
		ZipOutputStream zos =new ZipOutputStream(csum);
		BufferedOutputStream out =new BufferedOutputStream(zos);
		zos.setComment("a test of java zipping");
		
		BufferedReader in =new BufferedReader(new FileReader("D:\\test.txt"));
		zos.putNextEntry(new ZipEntry("D:\\test.txt"));
		int c;
		while((c=in.read())!=-1){
			out.write(c);
		}
		in.close();
		out.flush();
		out.close();
	}
}

你可能感兴趣的:(zip)