使用Java在Edge的新窗口中打开本地HTML文件

oknrviil  于 2023-02-02  发布在  Java
关注(0)|答案(1)|浏览(246)

如何在Edge的新窗口中打开本地HTML文件?我尝试了下面的代码,但HTML文件在同一窗口的不同选项卡中打开。我需要在单独的窗口中打开HTML文件。

Process p = rt.exec("cmd.exe /C start \"C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe" C:\\MyView.html");
h4cxqtbf

h4cxqtbf1#

ProcessBuilder不是终端模拟器。您不需要cmd.exe。您可以直接运行msedge.exe
我首先在Google中搜索microsoft edge命令行选项,然后找到:
Get list of Edge command line switches
这让我想到:
List of Chromium Command Line Switches
其中包括:

--new-window

因此,所需的最少代码为:

ProcessBuilder pb = new ProcessBuilder("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe",
                                       "--new-window",
                                       "C:\\MyView.html"); 
try {
    pb.start();
}
catch (IOException xIo) {
    xIo.printStackTrace();
}

相关问题