【发布时间】:2019-02-14 16:02:46
【问题描述】:
我有一个 zip 文件,我想将其转换为 gzip 并将其写回文件系统。我该怎么做?
我已经有了将文件压缩为 gzip 的代码:
private static void compressGzipFile(String file, String gzipFile) {
try {
FileInputStream fis = new FileInputStream(file);
FileOutputStream fos = new FileOutputStream(gzipFile);
GZIPOutputStream gzipOS = new GZIPOutputStream(fos);
byte[] buffer = new byte[1024];
int len;
while ((len=fis.read(buffer)) != -1) {
gzipOS.write(buffer, 0, len);
}
// Close resources
gzipOS.close();
fos.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
现在我需要将 zip 文件转换为 gzip 文件的代码。
【问题讨论】:
-
您无法将 zip 文件转换为 gzip 文件,因为 zip 文件可以包含文件,而 gzip 不能。您是否要改为 gzip 压缩文件(我怀疑这会有效)。