// 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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.