List of usage examples for java.nio.file.attribute AclFileAttributeView setAcl
void setAcl(List<AclEntry> acl) throws IOException;
From source file:Main.java
public static void main(String[] args) throws Exception { Path path = Paths.get("C:\\Java_Dev\\test1.txt"); AclFileAttributeView aclView = Files.getFileAttributeView(path, AclFileAttributeView.class); if (aclView == null) { System.out.format("ACL view is not supported.%n"); return;/*from w w w . ja va2 s . c o m*/ } UserPrincipal bRiceUser = FileSystems.getDefault().getUserPrincipalLookupService() .lookupPrincipalByName("brice"); Set<AclEntryPermission> permissions = EnumSet.of(AclEntryPermission.READ_DATA, AclEntryPermission.WRITE_DATA); AclEntry.Builder builder = AclEntry.newBuilder(); builder.setPrincipal(bRiceUser); builder.setType(AclEntryType.ALLOW); builder.setPermissions(permissions); AclEntry newEntry = builder.build(); List<AclEntry> aclEntries = aclView.getAcl(); aclEntries.add(newEntry); aclView.setAcl(aclEntries); }