import java.io.*;
import java.util.*;
public class ZipCompress {
public static void main(String[] args) throws IOException {
FileOutputStream f = new FileOutputStream("test.zip"); //把字符串写到test.zip的压缩文件中
CheckedOutputStream csum = new CheckedOutputStream(f, new Adler32());
ZipOutputStream zos = new ZipOutputStream(csum);
BufferedOutputStream out = new BufferedOutputStream(zos);
zos.putNextEntry(new ZipEntry("CompressedStrings.txt"));
byte[] stringBytes = "Here is the Strings would be Compressed".getBytes();
//stringBytes是要进行压缩的字符串
out.write(stringBytes);
out.flush();
out.close();
//Reading Zip file
FileInputStream fi = new FileInputStream("test.zip");
CheckedInputStream csumi = new CheckedInputStream(fi, new Adler32());
ZipInputStream in2 = new ZipInputStream(csumi);
BufferedInputStream bis = new BufferedInputStream(in2);
ZipEntry ze;
while((ze = in2.getNextEntry()) != null) {
int x;
while((x = bis.read()) != -1)
System.out.print((char)x);
}
}
}