JAVA IO - GZIP

GZip只用來將單個文件壓縮,而不是將多個文件壓縮。固然讀出gz只要用GZIPInputStream和FileOutputStream結合就能夠啦 java


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();
    }
}
相關文章
相關標籤/搜索