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