Determine if a file is executable on the OS

P

Philipp

Hello
Is there a way in java to determine if a file is executable on the OS?
I.e. if it is a File that I can call Runtime.exec(file) on?

Thanks Phil
 
A

Andrew Thompson

Philipp wrote:
...
Is there a way in java to determine if a file is executable on the OS?
I.e. if it is a File that I can call Runtime.exec(file) on?

Well.. you can always 'try' it. What does this 13 lines
of code tell you?

<sscce>
import java.io.*;

class LaunchAsCommand {

public static void main(String[] args) throws Exception {
File f = new File("LaunchAsCommand.java");
try {
Runtime.getRuntime().exec(f.getCanonicalPath());
} catch(IOException e) {
System.err.println( e.getMessage() );
}
}
}
</sscce>
 
P

Philipp

Andrew said:
Philipp wrote:
..
Is there a way in java to determine if a file is executable on the OS?
I.e. if it is a File that I can call Runtime.exec(file) on?

Well.. you can always 'try' it. What does this 13 lines
of code tell you?

<sscce>
import java.io.*;

class LaunchAsCommand {

public static void main(String[] args) throws Exception {
File f = new File("LaunchAsCommand.java");
try {
Runtime.getRuntime().exec(f.getCanonicalPath());
} catch(IOException e) {
System.err.println( e.getMessage() );
}
}
}
</sscce>

OK thanks. Juste wanted to know if I missed some part of the API.

Best regards
Phil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top