Search code examples
javafilefile-permissionsumask

java set file permissions to 777 while creating a file object


Possible Duplicate:
How can I set the umask from within java?

How do you set file permissions to 777(or any other arbitrary permission) while creating a file object in java?


Solution

  • If you set the umask(2) to 0 before starting the JVM, all files and directories created will be created with full permissions for everyone. This is probably a bad idea.

    You can use the File.setReadable(), File.setWritable APIs to fiddle with the mode bits after the file has been created. That's often good enough, if you're granting permissions; if you're trying to remove permissions from other users, then your permissions should probably be set very restrictively from the start. (umask(0777) before launching the JVM, then add permissions exactly where you want them.)