Create directory with write permissions for the group

前端 未结 5 1333
时光说笑
时光说笑 2021-01-11 11:44

I create a folder in my java program (running on linux) with mkdirs() function of File object. The problem is that the folder gets only read permissions for the group. I nee

5条回答
  •  迷失自我
    2021-01-11 12:18

    A very simple solution for this is:

    file.setExecutable(true, false);
    file.setReadable(true, false);
    file.setWritable(true, false);
    

    In above code, file is a File object.

    When you are creating a file set these permissions to a file setExecutable(true) will allow you to set that file as Executable for owner only. If you add one more parameter which I have added in above code file.setExecutable(true, false); will make Executable false for owner only, that means it will set permissions to all group / world.

    Tested and working on Debian and Windows XP.

提交回复
热议问题