如何在java中打开url [英] how to open url in java

查看:53
本文介绍了如何在java中打开url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。



如何在java中使用url类打开url



可以你帮帮我

Hi.

how to open the url with out using url class in java

can you pls help me

推荐答案

简单。



获取该URL并将其丢弃到操作系统。



操作系统将使用默认浏览器打开链接并显示给用户:



Simple.

Take that URL and Throw it against the Operating System.

the OS will use the default browser to open the link and show it to the user:

try {
  Desktop desktop = java.awt.Desktop.getDesktop();
  URI oURL = new URI("http://www.google.com");
  desktop.browse(oURL);
} catch (Exception e) {
  e.printStackTrace();
}





这是安全的,因为它没有任何浏览器的任何应用程序参考 - 操作系统决定。这也是处理PDF文件的好方法。



This is safe, cause it does not have any application reference to any browser or so - the OS decides. It's also a great way to deal with PDF files.


这是一个使用 Jakarta Commons [ ^ ]库: HTTP客户端教程 [ ^ ]。



问候,



Manfred
Here is a tutorial utilizing the Jakarta Commons[^] library: HTTP Client Tutorial[^].

Regards,

Manfred


String url_open ="your_url";
java.awt.Desktop.getDesktop().browse(java.net.URI.create(url_open));


这篇关于如何在java中打开url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆