Determine if a file is executable on the OS

Discussion in 'Java' started by Philipp, Oct 16, 2007.

  1. Philipp

    Philipp Guest

    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
    Philipp, Oct 16, 2007
    #1
    1. Advertising

  2. 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>

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via http://www.javakb.com
    Andrew Thompson, Oct 16, 2007
    #2
    1. Advertising

  3. Philipp

    Philipp Guest

    Andrew Thompson wrote:
    > 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
    Philipp, Oct 16, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kaith
    Replies:
    2
    Views:
    436
    Sandip Chitale
    Aug 16, 2003
  2. Tim Daneliuk
    Replies:
    29
    Views:
    1,116
    Tim Roberts
    Dec 22, 2006
  3. Replies:
    15
    Views:
    488
    Dave Thompson
    Aug 21, 2006
  4. pratap
    Replies:
    20
    Views:
    758
    Flash Gordon
    Mar 7, 2007
  5. Jason Cavett
    Replies:
    8
    Views:
    619
    Sanjay
    May 16, 2007
Loading...

Share This Page