📜  java设置文件夹权限-Java代码示例

📅  最后修改于: 2022-03-11 14:52:46.145000             🧑  作者: Mango

代码示例1
//if you need rw-rw-r  permissions 
public void setPermission(File file) throws IOException{
    Set perms = new HashSet<>();
    perms.add(PosixFilePermission.OWNER_READ);
    perms.add(PosixFilePermission.OWNER_WRITE);

    perms.add(PosixFilePermission.OTHERS_READ);
    perms.add(PosixFilePermission.OTHERS_WRITE);

    perms.add(PosixFilePermission.GROUP_READ);

    Files.setPosixFilePermissions(file.toPath(), perms);
}