JAVA IO - GZIP

GZip只用来将单个文件压缩,而不是将多个文件压缩。当然读出gz只要用GZIPInputStream和FileOutputStream结合就可以啦


import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.GZIPOutputStream;


public class GZIPTest {
    public static void main(String args[]) throws Exception{
    	FileInputStream fis = new FileInputStream("C:\\work\\hello\\helloworld.txt");
    	GZIPOutputStream  gos = new GZIPOutputStream(new FileOutputStream("C:\\work\\hello\\helloworld.gz"));
    	byte bs[] = new byte[1024];
    	int length = -1;
    	while((length= fis.read(bs)) != -1) {
    		gos.write(bs);
    	}
    	
    	fis.close();
    	gos.close();
    }
}




你可能感兴趣的:(JAVA IO - GZIP)