1. import java.nio.file.Files;
    2. import java.nio.file.Paths;
    3. import java.nio.file.attribute.PosixFilePermission;
    4. String path = "E:/data/data1/data2/aa.txt";
    5. //using PosixFilePermission to set file permissions 777
    6. Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
    7. //add owners permission
    8. perms.add(PosixFilePermission.OWNER_READ);
    9. perms.add(PosixFilePermission.OWNER_WRITE);
    10. perms.add(PosixFilePermission.OWNER_EXECUTE);
    11. //add group permissions
    12. perms.add(PosixFilePermission.GROUP_READ);
    13. perms.add(PosixFilePermission.GROUP_WRITE);
    14. perms.add(PosixFilePermission.GROUP_EXECUTE);
    15. //add others permissions
    16. perms.add(PosixFilePermission.OTHERS_READ);
    17. perms.add(PosixFilePermission.OTHERS_WRITE);
    18. perms.add(PosixFilePermission.OTHERS_EXECUTE);
    19. Files.setPosixFilePermissions(Paths.get(path), perms);