Reading Windows ACLs from Java

后端 未结 2 1010
野的像风
野的像风 2021-01-14 06:42

From within a Java program, I want to be able to list out the Windows users and groups who have permission to read a given file. Java has no built-in ability to read the Win

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-14 07:02

    mdma's answer covers the best approaches for Java 6 but here's a quick example for Java 7:

    Path file = Paths.get("c:\\test-file.dat");
    AclFileAttributeView aclFileAttributes = Files.getFileAttributeView(
        file, AclFileAttributeView.class);
    
    for (AclEntry aclEntry : aclFileAttributes.getAcl()) {
        System.out.println(aclEntry.principal() + ":");
        System.out.println(aclEntry.permissions() + "\n");
    }
    

提交回复
热议问题