Developer/Designer Notes

Java File Permissions

Posted by Kiran Mova on March 19, 2007

How to set the permissions of a file at runtime using Java? My requirement is very simple. I want to create a file with ‘777′ on linux.

With Java 1.6, I can use the method setWriteable(), setExecutable().

But prior to Java 1.6, there is no programmatic way to achieve this. The awkward work-around is to use the “Runtime.exec()” method and invoke ‘chmod 777′ on my file. The other workaround is to use JNI (I would never try that..) to invoke chmod. Check this thread at Java Forum.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>