How can I open any specific program in Java?

501 Views Asked by At

I want to open 2 different browsers with the same link. I have found how to open the default browser, but I want to open a non default browser as well, and I can't seem to find a way.

1

There are 1 best solutions below

4
clinomaniac On BEST ANSWER

To open non default browser, you'll need to know where it is installed and what browser. After that you can open it using the following command:

Runtime rt = null;
rt =  Runtime.getRuntime();
rt.exec("<PATH TO FIREFOX>\\firefox.exe <WEBSITE TO OPEN>");


<PATH TO FIREFOX> = Path to whatever browser you need to open.
firefox.exe = Launcher for the browser.
<WEBSITE TO OPEN> = Website URL you are trying to open.

To open private browsing: Use tag -private-window

Example:

rt.exec("<PATH TO FIREFOX>\\firefox.exe -private-window <WEBSITE TO OPEN>");