java set file permissions to 777 while creating a file object

Abhishek picture Abhishek · Jun 4, 2011 · Viewed 80k times · Source

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?

Answer

ratchet freak picture ratchet freak · Jun 4, 2011

3 methods are available:

setReadalble(boolean boolean)
setWritable(boolean,boolean)
setExecutable(boolean,boolean)

This will set the file to "0777"

String path = "SOME/PATH";

final File file = new File(path);
file.setReadable(true, false);
file.setExecutable(true, false);
file.setWritable(true, false);