在Windows上使用java8 NIO2设置文件权限有什么不同的方法吗?
file.setReadable(false, false);
file.setExecutable(false, false);
file.setWritable(false, false);发布于 2019-09-26 00:14:34
设置各种属性的File方法:setExecutable、setReadable、setReadOnly、setWritable被Files方法setAttribute(Path, String, Object, LinkOption...)所取代。
用法示例:
public void setFileAttributes() throws IOException {
Path path = ...
UserPrincipal user = path.getFileSystem().getUserPrincipalLookupService().lookupPrincipalByName("user");
AclFileAttributeView view = Files.getFileAttributeView(path, AclFileAttributeView.class);
AclEntry entry = AclEntry.newBuilder()
.setType(ALLOW)
.setPrincipal(user)
.setPermissions(Set.of(READ_DATA, EXECUTE, WRITE_DATA))
.build();
List<AclEntry> acl = view.getAcl();
acl.add(0, entry);
Files.setAttribute(path, "acl:acl", acl);
}有关更多详细信息,请参阅AclFileAttributeView。
https://stackoverflow.com/questions/58096912
复制相似问题