The example in this article describes how Java calls the browser to open a Web page. Share to everyone for your reference. The implementation methods are as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
Package Com.yifang.demo; Import Java.io.File; public class Openpagedemo {public static void main (string[] args) {try {//string url = ' http://www.baidu.com '; String url = "http://www.3lian.net/"; Java.net.URI URI = java.net.URI.create (URL); Gets the current system desktop extension java.awt.Desktop DP = Java.awt.Desktop.getDesktop (); Determine if the system desktop supports functionality to be performed if (dp.issupported (Java.awt.Desktop.Action.BROWSE)) {//file file = new file ("D:aa.txt");//dp.edit ( File)//Edit Files Dp.browse (URI);//Get system default Browser Open link//dp.open (file);//////////////////////Dp.print (files) by default . lang. NullPointerException e) {//This throws an exception e.printstacktrace () when the URI is empty ();} catch (Java.io.IOException e) {//This is unable to get the system default browser e.prints Tacktrace (); } } } |
I hope this article will help you with your Java programming.