CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Execute a file

  1. #1
    Join Date
    Oct 2006
    Location
    Mexico
    Posts
    12

    Execute a file

    Hello
    How can I execute a file or a program with java?
    Like executing a file.doc and then it opens with Microsoft Word
    or executin a file.exe from java

    Thank you

  2. #2
    Join Date
    Dec 2001
    Location
    Greece, Athens
    Posts
    1,015

    Re: Execute a file

    I suppose you mean you want to execute a java program. Java classes cannot be directly executed. One solution is to use Java Web Start or executable jars. There are also some programs that try to "package" java programs in an exe file. For more info you can visit this thread.
    Regards,
    Theodore
    Theodore
    Personal Web Page (some audio segmentation tools): www.di.uoa.gr/~tyiannak

  3. #3
    Join Date
    Oct 2006
    Location
    Mexico
    Posts
    12

    Re: Execute a file

    No, I want to execute a file or program from a java program, Like opening a web browser when someone push the button in my program or opening a file.xls with exel when the user do something in the java program.

  4. #4
    Join Date
    Apr 2001
    Location
    South Africa, Jo'burg
    Posts
    680

    Re: Execute a file

    Hi

    Depending on what version of JDK you are using there are 2 different methods of doing this. Prior to JDK 5 version, have a look at the Runtime class, from JDK 5 and up have a look at the ProcessBuilder class. Both these classes allow you to run command line commands directly from Java.

    Have a look HERE for how to use the Runtime class.

    Have a look HERE for a paper on using ProcessBuilder

    Hope This Helps
    Byron Tymvios

    Please use [ CODE ] and [/ CODE ] tags when posting code! See THIS on how to use code tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured