javafx--链接实现

方式一:

Desktop.getDesktop().browse(new URI(manualUrl));

在linux环境bug

 

方式二:

转载自:https://stackoverflow.com/questions/5226212/how-to-open-the-default-webbrowser-using-java/28807079#28807079

Windows:

Runtime rt = Runtime.getRuntime();
String url = "http://stackoverflow.com";
rt.exec("rundll32 url.dll,FileProtocolHandler " + url);
Mac

Runtime rt = Runtime.getRuntime();
String url = "http://stackoverflow.com";
rt.exec("open " + url);
Linux:

Runtime rt = Runtime.getRuntime();
String url = "http://stackoverflow.com";
String[] browsers = { "epiphany", "firefox", "mozilla", "konqueror",
                                 "netscape", "opera", "links", "lynx" };

StringBuffer cmd = new StringBuffer();
for (int i = 0; i < browsers.length; i++)
    if(i == 0)
        cmd.append(String.format(    "%s \"%s\"", browsers[i], url);
    else
        cmd.append(String.format(" || %s \"%s\"", browsers[i], url); 
    // If the first didn't work, try the next browser and so on

rt.exec(new String[] { "sh", "-c", cmd.toString() });
If you want to have multiplatform application, you need to add operation system checking(for example):

String os = System.getProperty("os.name").toLowerCase();
Windows:

os.indexOf("win") >= 0
Mac:

os.indexOf("mac") >= 0
Linux:

os.indexOf("nix") >=0 || os.indexOf("nux") >=0

 

posted on 2018-12-06 09:56 wenlin_gk 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/wenlin-gk/p/10075068.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值