我成功创建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();
}
}