我正在尝试使用公共写权限创建目录.为了简化我希望它拥有777
权限的东西.这是我的代码:
private static FileAttribute> DIR_PERMISSIONS; static { Set perms = new HashSet<>(); perms.add(PosixFilePermission.OWNER_WRITE); perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_EXECUTE); perms.add(PosixFilePermission.GROUP_WRITE); perms.add(PosixFilePermission.GROUP_READ); perms.add(PosixFilePermission.GROUP_EXECUTE); perms.add(PosixFilePermission.OTHERS_WRITE); perms.add(PosixFilePermission.OTHERS_READ); perms.add(PosixFilePermission.OTHERS_EXECUTE); DIR_PERMISSIONS = PosixFilePermissions.asFileAttribute(perms); } private Path ensurePath(LocalDate localDate) throws IOException { String year = String.valueOf(localDate.getYear()); String month = String.format("%02d", localDate.getMonthValue()); Path path = Paths.get(rootDirectory, year, month); return Files.createDirectories(path, DIR_PERMISSIONS); }
有了rootDirectory=/tmp/data
这应该创建文件夹一样/tmp/data/2016/01
,各有777
权限.相反,文件夹具有775
权限(drwxrwxr-x.),因此它们缺少公共写入.为什么这样工作?也许JVM需要特殊的参数才能设置这样的权限?我的系统是Fedora 24,app是标准的Spring Boot应用程序,由maven插件启动.