ROM*_*eer 11
从Java 7开始,您可以使用java.nio.file.Files.getLastModifiedTime(Path path):
Path path = Paths.get("C:\\1.txt");
FileTime fileTime;
try {
fileTime = Files.getLastModifiedTime(path);
printFileTime(fileTime);
} catch (IOException e) {
System.err.println("Cannot get the last modified time - " + e);
}
Run Code Online (Sandbox Code Playgroud)
在哪里printFileName可以看起来像这样:
private static void printFileTime(FileTime fileTime) {
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy - hh:mm:ss");
System.out.println(dateFormat.format(fileTime.toMillis()));
}
Run Code Online (Sandbox Code Playgroud)
输出:
10/06/2016 - 11:02:41
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27138 次 |
| 最近记录: |