这段代码非常简单。但是它什么也没做(除了输出我的打印语句)。
我在一个桌面Java应用程序中,并且将Chrome设置为默认浏览器。
我缺少什么?谢谢!
String url = "https://www.google.com/";
try {
if (java.awt.Desktop.isDesktopSupported())
System.out.println("yes");
else System.out.println("no");
java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
System.out.println("here");
} catch (IOException e) {
System.err.println("exception thrown");
e.printStackTrace();
}
System.out.println("done");
我的准确输出是这样的:
是的
这里
完成
编辑:我将默认浏览器从Chrome切换到Firefox,现在它可以正常工作。为什么Chrome不响应呢?
IOException
并不是唯一可能抛出的异常。 - Makoto