Executing applications from JAVA

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Executing applications from JAVA

  1. #1
    Join Date
    Jul 2007

    Executing applications from JAVA

    i'm working on some kind of file explorer whih should allow to open files.
    for example, user selected a file 123.doc or 456.jpg and wishes to open it. The programm should run an appropriate application (default) and open selected file. how can i implement this?
    i've tried to use
    Process p = Runtime.getRuntime.exec(command);

    where command is something like: "start "+absoluteFileName
    it works from command line(cmd) but doesn't work from java
    how can i solve that? Thanks

    moreover this should work on any OS. but i would be happy even if it works on windows first.

  2. #2
    Join Date
    Dec 2004
    San Bernardino County, California
    how does your program know what the "appropriate application" is?

  3. #3
    Join Date
    Feb 2007
    'command' can be either executable or something you normally typed in command line like "ping www.google.com". But there's other exec that taking an array of string, on which you can pass the executable name on index 0 and the subsequent arguments after. So these 2 codes produced the same effects:

    Process p = Runtime.getRuntime.exec("C:\\Program Files\\Internet Explorer\\iexplore.exe \"http://www.google.com\" ";


    String[] arrCmd = {"C:\\Program Files\\Internet Explorer\\iexplore.exe", "http://www.google.com"};
    Process p = Runtime.getRuntime.exec(arrCmd);

    Hope it helps.

Similar Threads

  1. Replies: 4
    Last Post: 03-19-2007, 01:00 AM
  2. Replies: 0
    Last Post: 03-13-2006, 03:41 PM
  3. Embed SMS Messaging in Java applications
    By Bob White in forum Java
    Replies: 2
    Last Post: 10-26-2005, 03:16 AM
  4. Deploying Java Applications
    By Gerry in forum Java
    Replies: 1
    Last Post: 11-22-2000, 11:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center