我可以处理 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 文件将保留 Modified 属性,但不会保留 Created 或 Accessed 属性。有没有办法做到这一点?