Java实现gzip的解压
时间: 2023-08-30 12:06:09 浏览: 47
Java中可以使用GZIPInputStream类来进行gzip压缩格式的解压。下面是一个简单的示例代码:
```java
import java.io.*;
import java.util.zip.GZIPInputStream;
public class GZipUtils {
public static void decompress(String gzipFile, String outputFolder) throws IOException {
byte[] buffer = new byte[1024];
FileInputStream fis = new FileInputStream(gzipFile);
GZIPInputStream gzis = new GZIPInputStream(fis);
FileOutputStream fos = new FileOutputStream(outputFolder);
int len;
while ((len = gzis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
gzis.close();
}
}
```
其中,gzipFile参数为需要解压的gzip文件路径,outputFolder参数为解压后文件输出的目录路径。调用该方法即可完成gzip文件的解压。