open file with default app

Discussion in 'Java' started by Christian Radermacher, Oct 3, 2005.

  1. hello there,

    I'm trying to open a file from a java application.
    The only method I found is Runtime.getRuntime.exec(String command)
    But isn't there something which says to the operting system to open a
    file with the default application?
    Or is there a command which is called by the operating system when I
    double-click a file? In this case which are these commands in windows
    and linux?
    Christian Radermacher, Oct 3, 2005
    #1
    1. Advertising

  2. Christian Radermacher wrote:

    > I'm trying to open a file from a java application.


    Can you be more specific about these 'files'? [1]

    > The only method I found is Runtime.getRuntime.exec(String command)
    > But isn't there something which says to the operting system to open a
    > file with the default application?


    Is there any command in the command line of the OS
    that 'opens a file in the default application'?

    If not, it is unlikely Java offers the same, if
    so, you can Runtime.exec("openInDefaultApp file")

    > Or is there a command which is called by the operating system when I
    > double-click a file? In this case which are these commands in windows
    > and linux?


    No Mac support?

    [1] What sort of 'files' are you wanting to open?
    I assume you are referring to documents rather than
    other executables? E.G., both these are effectively 'exe's
    - the default application for a Jar file is 'java'.
    - the default application for a JNLP file is JWS.
    as opposed to documents html, jpg, gif, doc, rtf,
    txt, java, xml, ..

    If you are referring specifically to documents it is
    easier, and if you can narrow down the document types,
    easier still.

    One example of launching (one) document type in in
    the default application is 'BrowserLauncher' for
    opening any URL in the user's default browser.
    Note that this might work particularly well for Win/IE
    users, as you can throw most documents into IE, and if
    it does not understand the format, it will pass it to
    any program that can.
    Andrew Thompson, Oct 3, 2005
    #2
    1. Advertising

  3. Christian Radermacher

    Hemal Pandya Guest

    Christian Radermacher wrote:
    > hello there,
    >
    > I'm trying to open a file from a java application.
    > The only method I found is Runtime.getRuntime.exec(String command)


    If you are running on NT or later,
    Runtime.getRuntime.exec("cmd.exe /c start " + fileName);
    should do the trick.

    On earlier windows versions IIRC start is an executable, so
    exec("start.exe " + fileName) might work.

    On linux, I don't know. But would love to find out what I can use.

    > But isn't there something which says to the operting system to open a
    > file with the default application?


    No, it is a function of the shell.
    Hemal Pandya, Oct 3, 2005
    #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. Matt
    Replies:
    2
    Views:
    1,394
    Toby Inkster
    Sep 25, 2004
  2. Johnny
    Replies:
    3
    Views:
    392
    J. Clifford Dyer
    Oct 24, 2006
  3. Replies:
    2
    Views:
    281
  4. Schüle Daniel

    File::open and File.open

    Schüle Daniel, Oct 23, 2006, in forum: Ruby
    Replies:
    4
    Views:
    187
    Rick DeNatale
    Oct 24, 2006
  5. Philipp
    Replies:
    6
    Views:
    131
    Lambik
    Jul 7, 2007
Loading...

Share This Page