-2

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?

vico
  • 17,051
  • 45
  • 159
  • 315

1 Answers1

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"
});

By terminal in Linux

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