Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > open file with default app

Reply
Thread Tools

open file with default app

 
 
Christian Radermacher
Guest
Posts: n/a
 
      10-03-2005
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?
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      10-03-2005
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.
 
Reply With Quote
 
 
 
 
Hemal Pandya
Guest
Posts: n/a
 
      10-03-2005

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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open a file with default handler app? andrei.avk@gmail.com Python 2 03-13-2008 12:07 AM
Re: how to open a file in some application using Tkinter i am usingTKINTER to create GUI application i want to know how to open a worddocument in open office or any other applicatio Fredrik Lundh Python 1 01-09-2008 10:40 AM
In windows, start default app associated with file type Philipp Perl Misc 6 07-07-2007 06:10 PM
File::open and File.open Brad Tilley Ruby 4 10-24-2006 09:34 PM
Directly open WinXP SP2 folders using Registry "App Paths" key default value Shaft Drive Computer Support 3 08-28-2005 05:43 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57