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的GZIP压缩库来压缩单个文件,并提供了完整的代码示例。通过结合GZIPInputStream和FileOutputStream,可以实现文件的压缩。

1082

被折叠的 条评论
为什么被折叠?



