版权声明 本文原创作者:谷哥的小弟作者博客地址:http://blog.csdn.net/lfdfhl Java源码 public void testGetFileTime() {try {String string = "E://test.txt";File file = new File(string);Path path = file.toPath();BasicFileAttributes basicFileAttributes = Files.readAttributes(path, BasicFileAttributes.class);String pattern = "yyyy-MM-dd HH:mm:ss";ZoneId zoneId = ZoneId.systemDefault();// 获取文件上次访问时间Instant lastAccessInstant = basicFileAttributes.lastAccessTime().toInstant();String lastAccessTime = DateTimeFormatter.ofPattern(pattern).withZone(zoneId).format(lastAccessInstant);System.out.println("获取文件上次访问时间:" + lastAccessTime);} catch (Exception e) {System.out.println(e);}}