I have a program (GUI = JavaFX), which scans my file system for specific XML report files and lists them in a table. These XML reports are rendered in a web browser by XSLT. Now I want to be able to click on such a report in my Java application and have it displayed in the browser. I already wrote the handler and the correct URL is determined. On my Windows system this is
file://localhost/C:/report.xml
The XML is not the problem. If I open it manually in my browser everything works fine. However if I use Google and ask how to open files in a browser it always gives me this:
java.awt.Desktop.getDesktop().
browse(new java.net.URI("file://localhost/C:/report.xml"));
As this is a good solution for http URLs (web sites), it always opens my XML file in my default text editor (e.g. Notepad++). So the browse method of the Desktop doesn't really force the browse, but merely falls back to a default open operation.
So the question is: How can I force Java to open the XML in the browser similar to the Windows function "Open with >"?
Here an sscce (which should try to access the file in a browser, even though it doesn't exist):
public class XMLOpener {
public static void main(String[] args)
{
String fileURL = "file://localhost/C:/report.xml";
try {
java.awt.Desktop.getDesktop().browse(new java.net.URI(fileURL));
} catch (Exception e) {}
}
}