Java将组添加到目录权限列表

Java将组添加到目录权限列表,java,permissions,directory,Java,Permissions,Directory,我正在努力将特定组权限授予使用file.mkdirs()创建的目录结构的顶层。我已经找到了如何更改目录的所有者,但这不是我所需要的,我需要在那些有权访问目录的人的列表中添加一个组。具体来说,这是针对Windows系统和我正在创建的文件夹结构。我需要将组添加到文件夹的安全部分,以允许它们读取和写入所有子目录。这可能吗?感谢@Robyte为我指明了正确的方向。下面是未完成的代码,我需要做一些重构,但它得到了我所需要的大部分 try { Path path = file.toPath();

我正在努力将特定组权限授予使用
file.mkdirs()
创建的目录结构的顶层。我已经找到了如何更改目录的所有者,但这不是我所需要的,我需要在那些有权访问目录的人的列表中添加一个组。具体来说,这是针对Windows系统和我正在创建的文件夹结构。我需要将组添加到文件夹的安全部分,以允许它们读取和写入所有子目录。这可能吗?

感谢@Robyte为我指明了正确的方向。下面是未完成的代码,我需要做一些重构,但它得到了我所需要的大部分

try {
    Path path = file.toPath();

    AclFileAttributeView aclView = Files.getFileAttributeView(path, AclFileAttributeView.class);
    if(aclView == null)
    {
        System.out.format("ACL View not supported");
    }

    UserPrincipal up = FileSystems.getDefault().getUserPrincipalLookupService().lookupPrincipalByName("username");
    Set<AclEntryPermission> aep = EnumSet.of(READ_DATA,WRITE_DATA);

    AclEntry builder = AclEntry.newBuilder().setType(AclEntryType.ALLOW).
            setPrincipal(up).setPermissions(aep).build();

    List<AclEntry> acl = aclView.getAcl();
    acl.add(0,builder);
    aclView.setAcl(acl);
} catch (IOException ex) {
    Logger.getLogger(PermissionsUtil.class.getName()).log(Level.SEVERE, null, ex);
}
试试看{
路径路径=file.toPath();
AclFileAttributeView aclView=Files.getFileAttributeView(路径,AclFileAttributeView.class);
if(aclView==null)
{
System.out.format(“不支持ACL视图”);
}
UserPrincipal up=FileSystems.getDefault().getUserPrincipalOkupService().lookupPrincipalByName(“用户名”);
Set aep=EnumSet.of(读取数据、写入数据);
acentry builder=acentry.newBuilder().setType(acentrytype.ALLOW)。
setPrincipal(up).setPermissions(aep).build();
List acl=aclView.getAcl();
acl.add(0,生成器);
aclView.setAcl(acl);
}捕获(IOEX异常){
Logger.getLogger(PermissionsUtil.class.getName()).log(Level.SEVERE,null,ex);
}

Heer是一些有用的链接:Oracle的Java教程主题和@gfos上的文件API,这不是我想要的。我不想改变主人。我还应该补充一点,这是针对Windows系统的。的示例代码应该可以帮助您入门。首先尝试读取和打印现有ACE,以查看需要哪些权限和标志。