【发布时间】:2013-01-05 11:15:30
【问题描述】:
我成功创建了具有预期内容的gz 存档,但是如何在存档中设置文件名?
我的意思是,如果创建存档myfile.gz,其中的文件将命名为“myfile”,但我想将其命名为源文件,例如“1.txt”
当前代码:
public static void gz() throws FileNotFoundException, IOException {
GZIPOutputStream out = null;
String filePaths[] = {"C:/Temp/1.txt","C:/Temp/2.txt"};
try {
out = new GZIPOutputStream(
new BufferedOutputStream(new FileOutputStream("C:/Temp/myfile.gz")));
RandomAccessFile f = new RandomAccessFile(filePaths[0], "r");
byte[] b = new byte[(int)f.length()];
f.read(b);
out.write(b, 0, b.length);
out.finish();
out.close();
} finally {
if(out != null) out.close();
}
}
【问题讨论】:
标签: java compression gzip archive apache-commons