By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,191 Members | 1,067 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,191 IT Pros & Developers. It's quick & easy.

How to open an external file from a Java Prog?

P: n/a
Hi,
I need to open an external file, such as *.htm from a Java program. I
need to open this file by the default program that handles this
extension on the machine. So *.htm should always be opened by Netscape
if that is the default browser on the machine.

I figured out how to do this on NT but could not find an equivalent
command on Linux.

Here is what I did on NT.

getRuntime().exec("cmd /c start myFile.htm");

This line opens up myFile.htm in IE on NT. Do you know the equivalent of
this command on Linux and Solaris? Any better solutions????
KB.

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Kathy Benson wrote:
Hi,
I need to open an external file, such as *.htm from a Java program. I
need to open this file by the default program that handles this
extension on the machine. So *.htm should always be opened by Netscape
if that is the default browser on the machine.

I figured out how to do this on NT but could not find an equivalent
command on Linux.

Here is what I did on NT.

getRuntime().exec("cmd /c start myFile.htm");

This line opens up myFile.htm in IE on NT. Do you know the equivalent of
this command on Linux and Solaris? Any better solutions????


Most OS's don't support the notion of file type association at their
command level. Indeed, the only one that really does in this manner is
Windows.

There are two possible solutions. One is going the platform-specific
route, and writing different code for each platform to figure out what
to do. On some Linux distros, for example, you may be able to call
"htmlview" and let it figure out what browser to open. On OS/2, I'd
create a WPUrl object in <WPNowhere> and then launch it, letting the OS
again decide which viewer to use. For other platforms, you may have to
hard-code the external program to use.

The other option is to add a setup dialog to your application that
allows the user to specify the application to use, and keep your own
MIME-type/viewer database, akin to what Netscape/Mozilla does for
"Helper Applications".

HTH!

Brad BARCLAY

--
=-=-=-=-=-=-=-=-=
From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
The jSyncManager Project: http://www.jsyncmanager.org


Jul 17 '05 #2

P: n/a
I'm fairly certain there is no such thing as a "default application"
for a file type in UNIX.

Also, note that using commands like getRuntime().exec() reduces the
portability of your Java application.
Jul 17 '05 #3

P: n/a
But can't you use System.getProperty("os.name");
to determine what program to run?

"Steve Lieberman" <sl@digilevel.com> wrote in message news:be**************************@posting.google.c om...
I'm fairly certain there is no such thing as a "default application"
for a file type in UNIX.

Also, note that using commands like getRuntime().exec() reduces the
portability of your Java application.

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.