Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 Java 1.7 中,我读到有直接方法可以获取文件的最后修改时间,但我不知道应该将哪些值传递给 LinkOptions 的参数。我很欣赏最简单的例子。谢谢你!
Path file = ... BasicFileAttributes attrs = Files.readAttributes(file, BasicFileAttributes.class); FileTime time = attrs.lastModifiedTime();
Java 文档BasicFileAttributes#lastModifiedTime
或直接:
File file = new File(...); FileTime time = Files.getLastModifiedTime(file.toPath());