Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Determine if a file is executable on the OS

Thread view: 
Philipp - 16 Oct 2007 10:51 GMT
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
Andrew Thompson - 16 Oct 2007 11:27 GMT
...
>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>

Signature

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

Philipp - 16 Oct 2007 12:44 GMT
> ..
>> Is there a way in java to determine if a file is executable on the OS?
[quoted text clipped - 18 lines]
> }
> </sscce>

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

Best regards
Phil


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.