Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

open file with default app

Thread view: 
Christian Radermacher - 03 Oct 2005 11:49 GMT
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?
Andrew Thompson - 03 Oct 2005 12:13 GMT
> 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.
Hemal  Pandya - 03 Oct 2005 14:20 GMT
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.