Java open page

Source: Internet
Author: User

[Java] // /////////////////// Bare Bones Browser Launch /// Version 1.5 (December 10,200 5) /// By Dem Pilafian /// supported: Mac OS X, GNU/Linux, Unix, windows XP /// available for free /////////////////////////////// //// // //// /// *** @ author Dem Pilafian * @ author John kristian */import java. lang. reflect. method; public class nima {public static void openUR L (String url) {try {browse (url);} catch (Exception e) {}} private static void browse (String url) throws Exception {// get the operating System name String osName = System. getProperty ("OS. name "," "); if (osName. startsWith ("Mac OS") {// open method of Apple Class fileMgr = Class. forName ("com. apple. eio. fileManager "); Method openURL = fileMgr. getDeclaredMethod ("openURL", new Class [] {String. class}); openURL. invoke (null, new O Bject [] {url});} else if (osName. startsWith ("Windows") {// windows open mode. Runtime.getruntime(cmd.exe c ("rundll32 url. dll, FileProtocolHandler "+ url);} open else {// String [] browsers = {" firefox "," opera "," konqueror ", "epiphany", "mozilla", "netscape"}; String browser = null; for (int count = 0; count <browsers. length & browser = null; count ++) // run the code and exit after brower has a value. // if the process is successfully created, = 0 indicates that the process ends normally. If (runtime.getruntime(cmd.exe c (new String [] {"which", browsers [count]}). waitFor () = 0) browser = browsers [count]; if (browser = null) throw new Exception ("cocould not find web browser "); else // This value has successfully obtained a process. Runtime.getruntime(cmd.exe c (new String [] {browser, url}) ;}} public static void main (String [] args) throws InterruptedException {www.2cto.com String url = "http://www.baidu.com/"; nima. openURL (url); Thread. sleep (1000); url = "http://www.sina.com/"; nima. openURL (url) ;}} opens the second page at intervals. You can try sleep for a while.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.