您的位置:首页 > 编程语言 > Java开发

获取POSIX视图属性---POSIX

2013-12-30 17:14 387 查看
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上运行
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息