有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (1) 个答案

  1. # 1 楼答案

    设置各种属性的File方法:setExecutablesetReadablesetReadOnlysetWritableFiles方法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