【发布时间】:2010-10-21 06:42:56
【问题描述】:
int BUFFER_SIZE = 4096;
byte[] buffer = new byte[BUFFER_SIZE];
InputStream input = new GZIPInputStream(new FileInputStream("a_gunzipped_file.gz"));
OutputStream output = new FileOutputStream("current_output_name");
int n = input.read(buffer, 0, BUFFER_SIZE);
while (n >= 0) {
output.write(buffer, 0, n);
n = input.read(buffer, 0, BUFFER_SIZE);
}
}catch(IOException e){
System.out.println("error: \n\t" + e.getMessage());
}
使用上面的代码,我可以成功地提取 gzip 的内容,尽管提取的文件的文件名正如预期的那样总是current_output_name(我知道它是因为我在代码中声明它是这样的)。我的问题是当文件仍在存档中时,我不知道如何获取文件的文件名。
虽然 java.util.zip 提供了一个 ZipEntry,但我无法在 gzip 文件上使用它。 有什么选择吗?
【问题讨论】: