// Get the permission in a string formString rwxFormPermissions = "rw-r-----";// Convert the permission in the string form to a Set of PosixFilePermissionSet<PosixFilePermission> permissions = PosixFilePermissions.fromString(rwxFormPermissions);// Update the permissionsposixView.setPermissions(permissions);

Alternatively, you can also create a Set of PosixFilePermission enum constants directly and set it as the file permissions, like so:

Set<PosixFilePermission> permissions = EnumSet.of(OWNER_READ, OWNER_WRITE, GROUP_READ);posixView.setPermissions(permissions);

Listing 10-19 demonstrates how to read and update POSIX file permissions for a file named luci on UNIX-like platforms. If the file does not exist, the program outputs the stack trace ...

Get Beginning Java 8 Language Features: Lambda Expressions, Inner Classes, Th reads, I/O, Collections,and Streams now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.