Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open a file in an external default program 1

Status
Not open for further replies.

zippy007

Programmer
Dec 9, 2002
4
0
0
BE
Alright... this is what I wish to do, coding in java :

I work with html, pdf, ... files in my java program and I wish to be able, within the program, to open those files launching the default external program defined by the user in his operation system (like for exemple nescape or iexplorer to open a html file, acrobat for a pdf, ...).

Does anyone knows how I can do that?

Thanks in advance

Zippy 007
 
i am not sure what u want but i guess u want to call an external application from a java program

well if so the take a look at this peice of code

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("iexplore
just put these to lines in ur main method

-
Aravind
 
This does not work... I have also tried this :

Runtime.getRuntime().exec("start myFile.html");

that does not work either...
The start command is ok for the dos, but win 2000 does not seem to want it.

Executing your code lines, I go this :
java.io.IOException: CreateProcess: iexplore error=2


Other thing is I don't simply need to launch the program to view my file, I need to find somewhere what is the default program for my file extension before launching it. And this should work on different operating system...

thanks :)

Cécile Hayez
 
I don't think that will work based on the nature of operating systems. I would check around the system properties features of Java, but I highly doubt checking for default programs can be platform independent. Just a thought.

JavaDude32
 
JavaDude's right. Does UNIX have a default application to run a .pdf file, or an .html file? Not that I've ever seen. What you're trying to do sounds like it's Windows-specific. And in Windows, you can run an external process using "start", and it starts in the application associated with that type. So "start will open up the web page in internet explorer or netscape, whichever is the default on the system, "start my.pdf" will open my.pdf up in Adobe Acrobat, etc.
 
Check out a product called JConfig. It has the type of external file launcher you're looking for:


It comes with source and is free for most developers. The source file tester.java that comes with it does what you describe.
 
Can i somehow start a new window every time i call

rundll32 url.dll,FileProtocolHandler some_url
 
Ok... had to stop working on this for a while, now I'm back to it...

I wish to try to use the JConfig sources, but can someone tell me where I can easily find the packages needed to compile the JConfig sources? (like com.apple.cocoa.foundation, com.apple.mrj.macos.carbon)
I don't seem to be able to find them :p

I'm using it on win 2000 .

Thank you

Cécile Hayez
 
You don't need to compile all of JConfig. They include source for apple and unix.

In the source directory there's a com/jconfig directory that contains three directories:
mac, nix and win. Delete the mac and nix directories and compile only what's in the jconfig and win directories.
"When you have eliminated the impossible, whatever remains, however
improbable, must be the truth." ~ Arthur Conan Doyle
 
hi! i had the same problem, but here is how to do it in win2000:

try {
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("cmd /c start yourFile");
} catch(Exception e) {
System.out.println(e);
}

remember to use full path and extension of the file.

/frank
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top