How to force an html document to always be opened by the browser?

2

I'm developing a java application for a college job and I have a help section for the user where I open a html page in the browser, or at least should open it.

The point is that if files with .html extension were by default of the system to be opened by a browser, as well it will be opened by the browser, however if this extension is linked by default, for example, to an editor of text it will open in the text editor revealing the code.

I wonder if there is a java mode of a html document only to be opened by the browser. The code I use is the one below:

Desktop desktop = null;
desktop = Desktop.getDesktop();
URI url = null;

File file = new File("src/ajuda/index.html");

try {

    url = new URI(file.toURI().toString());
    desktop.browse(url);

} catch (URISyntaxException | IOException ex) {
    Logger.getLogger(Teste.class.getName()).log(Level.SEVERE, null, ex);
}
    
asked by anonymous 07.07.2015 / 15:18

2 answers

3

I do not understand java, but I program in other languages. I do not know where it is running your code, tb I do not know if it is possible ... but ...

And if instead of giving you a command letting the OS decide where to open your HTML, you would call the browser directly, passing the html path as a parameter, type this:

run ("c: \ program files \ ie \ iexplorer.exe seuhtml.html").

This will always open your HTML in the browser. If you have a server running on the machine, just call the default path of your html:

execute ("c: \ program files \ ie \ iexplorer.exe link ).

It's an idea.

    
07.07.2015 / 15:46
2

I do not think this is possible primarily because by doing so you would be taking away the power of the user to control the actions that happen on your own computer. Following usability standards, the user should choose how and with which programs he will open / view certain type of file. What you can do is display messages advising the best way to open / view the file;

    
07.07.2015 / 15:36