I'm looking for a code fragment, using which I must be to change the file permissions on unix. My project runs on java 1.4.2 ..
just a sample code example or methods which needs to be used will do..
Regards, Senny
I'm looking for a code fragment, using which I must be to change the file permissions on unix. My project runs on java 1.4.2 ..
just a sample code example or methods which needs to be used will do..
Regards, Senny
Just to be extra clear: Java 1.6 introduces getters/setters like File.canExecute() and File.setExecutable(boolean) for file permissions. So one solution is to use the latest JDK instead of the 1.4 you mentioned. Otherwise, as suggested, you can try to backport, or call out to platform-specific commands.
You could also look at the Gnu ClassPath implementation of java.lang.File
They implemented the function based on JNI calls:
VMFile.java declares the call:
native/jni/java-io/java_io_VMFile.c does implement the desired function...
So... if you really want it, it is possible to implement it, by looking at the source of cpio.c: it calls
chmod
from libc standard library (LibGW32C does port some of those functions to Windows)You're not the only one: How to change the file's permission and last modified in Java?
You could, in principle, use Runtime.exec("chmod ...") if the existing java.io.File methods aren't enough. But it wouldn't be portable.