- 获取所有属性
BasicFileAttributes attr = null; Path path = Paths.get("F:/cn/icer/ws/client/Business.java"); try { attr = Files.readAttributes(path, BasicFileAttributes.class); } catch (Exception e) { e.printStackTrace(); } show("File size: " + attr.size()); show("File creation time: " + attr.creationTime()); show("File was last accessed at: " + attr.lastAccessTime()); show("File was last modified at: " +attr.lastModifiedTime()); show("Is directory? " + attr.isDirectory()); show("Is regulat file? " + attr.isRegularFile()); show("Is symbolic link? " + attr.isSymbolicLink()); show("Is other? " + attr.isOther());
- 获取单一属性
Path path = Paths.get("F:/cn/icer/ws/client/Business.java"); try { long size = (long) Files.getAttribute(path, "basic:size", LinkOption.NOFOLLOW_LINKS); show("Size: " + size); } catch (Exception e) { e.printStackTrace(); }
- Basic 属性名列表:
1) lastModifiedTime 2) lastAccessTime 3) creationTime 4) size 5) isRegularFile 6) isDirectory 7) isSymbolicLink 8) isOther 9) fileKey
- notes:以上show()是指:
private static void show(Object obj) { System.out.println(obj); }
获取属性---basic
最新推荐文章于 2023-01-17 09:36:39 发布