在Java中,有没有一种方法可以在文件添加到zip存档时保留文件的已创建和已访问属性?

在Java中,有没有一种方法可以在文件添加到zip存档时保留文件的已创建和已访问属性?,java,archive,zipoutputstream,Java,Archive,Zipoutputstream,我可以处理Modified(lastModified)属性,这意味着在存档中我可以保留文件的Modified属性。 以下是一个示例: ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream( new FileOutputStream(outFilename))); File f = new File(filename); long longLastMod = f.lastModified(); FileInputStr

我可以处理Modified(lastModified)属性,这意味着在存档中我可以保留文件的Modified属性。
以下是一个示例:

ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream( new FileOutputStream(outFilename)));
File f = new File(filename);
long longLastMod = f.lastModified();
FileInputStream in = new FileInputStream(filename);
// Add ZIP entry to output stream.
ZipEntry ze = new ZipEntry(filename);
ze.setTime(longLastMod);  // the "magic" to store the Modified date/time of the file
out.putNextEntry( ze );
// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
}
out.closeEntry();
in.close();
out.close();
现在,输出Zip文件将保留修改后的属性,但不会保留创建或访问的属性。 有没有办法做到这一点

有没有办法做到这一点

不可能。简单地说:zip目录不支持这些属性

但是,您可以使用
setExtra(byte[])
并在那里存储您需要的任何信息。不幸的是,您需要一个自定义提取器来保留这些属性


希望这有帮助

有了Java8,这是可能的,请参阅