Create PosixFilePermissions from string rwxr-x---
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Set;
public class Test {
public static void main(String[] args) throws Exception {
FileSystem fileSystem = FileSystems.getDefault();
Path directory = fileSystem.getPath("./newDirectoryWPermissions");
Set<PosixFilePermission> perms = PosixFilePermissions
.fromString("rwxr-x---");
FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions
.asFileAttribute(perms);
Files.createDirectory(directory, attr);
}
}
Related examples in the same category