gpt4 book ai didi

java - 如何从 Java 应用程序中启动标准浏览器?

转载 作者:行者123 更新时间:2023-11-30 09:55:53 25 4
gpt4 key购买 nike

如何使用带有 Java 的系统标准浏览器打开 URL?

我目前使用这段代码打开一个特定的 URL(本地存储的 html 文件),当我用我的 IDE (Eclipse) 运行应用程序时它工作正常,但在捆绑软件后,它不再工作了。

    url = MainWindow.class.getResource("mySite.html");

helpMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
java.awt.Desktop.getDesktop().browse(url.toURI());
}
catch (URISyntaxException e1) {
e1.printStackTrace();
}
catch (IOException e1) {
e1.printStackTrace();
}
}
});

有什么建议吗?非常感谢!

最佳答案

but after bundling the software, it doesn't work any more.

您无法浏览到指向 JAR 文件内资源的 URL。您需要提取资源(只需使用 getResourceAsStream() 获取 InputStream)并将其存储在其他地方(as temp file?),然后浏览它。

关于java - 如何从 Java 应用程序中启动标准浏览器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2624655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com