• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDIC opening any file with the browser

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is on Mac OS X 10.5.5 using JDIC with Java 1.5 and Firefox is my default browser.

I'm trying to open up an XML file on the local file system using Firefox instead of the default XML viewer(there's a stylesheet). I don't want to set Firefox as my default XML viewer because for another part of this program, I DO want to open XML up with an editor.

Here's some code I've tried along with the results:

Desktop.browse("http://www.cnn.com"); //works fine

Desktop.browse("/Users/iAmAFile.xml");//Malformed URL expection:no Protocol

Desktop.browse("file:///Users/file.xml);
//Desktop Exception: Failed to Launch the Default Browser
//Also, this is what is in the URL bar when I manually open the file with
//firefox

Thanks for your help.

-Sam
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out Runtime.exec and ProcessBuilder. Simply running "firefox mypathto/myfile.xml" should work, as long as firefox is on your path.
 
Sam Latious
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response. I think that would work on my machine, but I need this to work on Windows machines, ones that may use either firefox or IE. My bad for not putting that into the original post. I did think of a way to do this last night though.

This assumes that the machine is set up so that the default browser and the default program for opening HTML files is the same thing.

I plan on generating a small html file at runtime which will redirect to whatever XML file I want to show.

Desktop.open("temp.html");
//asks the OS to open the file with whatever opens html files, hopefully
//the browser

Contents of temp.html:
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=/path/to/file.xml">
</head>
</html>
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The cross-platform Bare Bones Browser Launcher might also be helpful.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic