如何将 File.setReadable 映射到 NIO Path 操作

How to map File.setReadable to NIO Path operations

实现File.setReadable独立于平台的'new'方法是什么?是 PosixFilePermissions 还是其他?

您应该使用 Files class 的 setPosixFilePermissions 方法,例如:

Set<PosixFilePermission> permissions = new HashSet<PosixFilePermission>();
permissions.add(PosixFilePermission.OWNER_READ);
permissions.add(PosixFilePermission.OWNER_WRITE);
permissions.add(PosixFilePermission.OWNER_EXECUTE);
permissions.add(PosixFilePermission.GROUP_READ);
permissions.add(PosixFilePermission.GROUP_WRITE);
permissions.add(PosixFilePermission.GROUP_EXECUTE);
permissions.add(PosixFilePermission.OTHERS_READ);
permissions.add(PosixFilePermission.OTHERS_WRITE);
permissions.add(PosixFilePermission.OTHERS_EXECUTE);
Files.setPosixFilePermissions(Paths.get("file.ext"), permissions);