Java opens browser for Windows system

Source: Internet
Author: User

There are two ways to get Baidu data, one is to use the URL to get from the stream, the other is to open the browser directly. Text recognition (OCR) and then transcoding can be fast Baidu

     Public Static voidMain (string[] args)throwsIOException {//URL link AddressString localpath = "http://www.baidu.com/s?tn=ichuner&lm=-1&word=" +Urlencoder.encode ("Jiangsu provincial capital", "gb2312") + "&rn=1"; URL URL=NewURL (LocalPath); //get the returned data directly based on the URLBufferedReader breaded =NewBufferedReader (NewInputStreamReader (Url.openstream (), "UTF-8"));  while(Breaded.readline ()! =NULL) {//Print this dataSystem.out.println (Breaded.readline ()); }        //Get system TypeString osname = System.getproperty ("Os.name", "" ");        System.out.println (Osname); if(Osname.startswith ("Windows")) {//if the Windows system            runtime.getruntime (). exec("rundll32 Url.dll,fileprotocolhandler" + localpath);//Open Browser        }    }

Runtime.getruntime (). EXEC () is the command that calls the computer

Java opens browser for Windows system

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.