- Files.readAttributes()
Path path = Paths.get("/home/icer/note.txt"); PosixFileAttributes attr = null; try { attr = Files.readAttributes(path, PosixFileAttributes.class); } catch (Exception e) { e.printStackTrace(); } System.out.println("File owner: " + attr.owner().getName()); System.out.println("File group: " + attr.group().getName()); System.out.println("File permissions: " + attr.permissions().toString());
- Files.getFileAttributeView().readAttributes()
Path path = Paths.get("/home/icer/note.txt"); PosixFileAttributes attr = null; try { attr = Files.getFileAttributeView(path, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS).readAttributes(); } catch (Exception e) { e.printStackTrace(); } System.out.println("File owner: " + attr.owner().getName()); System.out.println("File group: " + attr.group().getName()); System.out.println("File permissions: " + attr.permissions().toString());
- POSIX的属性可以被要求以下列名称
1) group 2) permissions
- notes:在Unix或linux上运行
获取POSIX视图属性---POSIX
最新推荐文章于 2024-07-25 11:18:42 发布