I need to set execute permition on Linux script file using java 1.4. I would prefer to use java native library. If it is not possible with native library what is lightweight lib that allows to do it?
Asked
Active
Viewed 81 times
1 Answers
1
JAVA5
and prior there is workaround using exec
extracted from here:
public static void runCmd (String[] cmd) {
try {
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader r = new BufferedReader(
new InputStreamReader (
p.getInputStream()
)
);
} catch(Exception e) {
}
}
USE
runCmd(new String[] {
"/bin/chmod",
"755",
"/path/to/your/script"
});
UP TO JAVA6
For permissions use File::setExecutable(boolean [, boolean])
File file = new File("/your/path/to/file/file_script.sh");
file.setExecutable(true);
Check this MKYONG permissions tutorial

Community
- 1
- 1

Jordi Castilla
- 26,609
- 8
- 70
- 109
-
Does it work for Java versions prior 1.6? – Stanislav Sep 08 '15 at 08:36
-
Yes in `Java6`, not in `Java5`. But [here](http://stackoverflow.com/questions/11095728/set-file-permission-in-java-5) you can find a workaround for `Java5` – Jordi Castilla Sep 08 '15 at 08:40
-
1The probvlem is, that version is 1.4 for this question, not even 1.5 – Stanislav Sep 08 '15 at 08:43
-
1Both are right.... havn't seen that. I updated my answer – Jordi Castilla Sep 08 '15 at 08:44