如何在Java中打开任何特定程序?

时间:2018-03-14 19:13:59

标签: java running-other-programs

我想用相同的链接打开2个不同的浏览器。我已经找到了如何打开默认浏览器,但我想打开一个非默认浏览器,我似乎无法找到方法。

1 个答案:

答案 0 :(得分:1)

要打开non default浏览器,您需要知道它的安装位置和浏览器。之后,您可以使用以下命令打开它:

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.

要打开隐私浏览:请使用代码-private-window

示例:

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