Home arrow static arrow Java Programming [Archive] - running external programms
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - running external programms
This topic has 3 replies on 1 page.

Posts:7
Registered: 4/28/04
running external programms  
Jul 3, 2004 3:53 AM



 
Hello!

I want to open html file in a default browser from Java code. How can I do it?
Same thing, but pdf file in Acrobat (if Acrobat is system default viewer of course) ?

Thanks for help!
 

Posts:14
Registered: 1/18/04
Re: running external programms  
Jul 3, 2004 4:42 AM (reply 1 of 3)



 
Hi.

You can use the Runtime.getRuntime.exec(String s) ( Read the API for this, as there are more methods available).

If you are using windows this should work (of corse the c:/ path should be replaced by the real path of your files).
The files will open in the default filehandler for the files. This is not the ideal solution if you aren't running windows (it wont work :D )

Runtime.getRuntime().exec("rundll32.exe url.dll,FileProtocolHandler "+"c:/yourHTMLFile.html")
and
Runtime.getRuntime().exec("rundll32.exe url.dll,FileProtocolHandler "+"c:/yourPDFFile.pdf")

You can run any program with this call, ie.
Runtime.getRuntime().exec("c:/autoexec.bat"); //executes c:\autoexec.bat
or
Runtime.getRuntime().exec("Notepad.exe newDoc.txt"); //executes Notepad and opens newDoc.txt

Hope this helps

Poul Krogh
 

Posts:24,036
Registered: 2/3/03
Re: running external programms  
Jul 3, 2004 5:30 AM (reply 2 of 3)



 
Hello!

I want to open html file in a default browser from
Java code. How can I do it?
Same thing, but pdf file in Acrobat (if Acrobat is
system default viewer of course) ?

Thanks for help!

Read this article: [url=http://www.javaworld.com/javaworld/javatips/jw-javatip66.html]Control browsers from your Java application[/url]
 

Posts:7
Registered: 4/28/04
Re: running external programms  
Jul 5, 2004 9:50 PM (reply 3 of 3)



 
Thank you thank you thank you!
 
This topic has 3 replies on 1 page.