我想更改二进制文件的修改时间戳。这样做的最佳方法是什么?
打开和关闭文件是一个不错的选择吗? (我需要一个解决方案,其中时间戳的修改将在每个平台和 JVM 上更改)。
原文由 sinuhepop 发布,翻译遵循 CC BY-SA 4.0 许可协议
我的 2 美分,基于 @Joe.M 的回答
public static void touch(File file) throws IOException{
long timestamp = System.currentTimeMillis();
touch(file, timestamp);
}
public static void touch(File file, long timestamp) throws IOException{
if (!file.exists()) {
new FileOutputStream(file).close();
}
file.setLastModified(timestamp);
}
原文由 Mmmh mmh 发布,翻译遵循 CC BY-SA 3.0 许可协议
4 回答1.4k 阅读✓ 已解决
4 回答1.3k 阅读✓ 已解决
1 回答2.6k 阅读✓ 已解决
2 回答741 阅读✓ 已解决
2 回答1.7k 阅读
2 回答1.7k 阅读
2 回答1.3k 阅读
File 类有一个 setLastModified 方法。这就是 ANT 所做的。