Small examples of reptiles

Source: Internet
Author: User

 PackageCom.textPa.two;;;;ImportJava.nio.charset.Charset;Importorg.apache.http.HttpEntity;ImportOrg.apache.http.HttpResponse;ImportOrg.apache.http.client.methods.HttpGet;Importorg.apache.http.impl.client.CloseableHttpClient;Importorg.apache.http.impl.client.HttpClients;Importorg.apache.http.util.EntityUtils; Public classRetrivepage { Public Static voidMain (string[] args) {closeablehttpclient httpClient=Httpclients.createdefault ();//httpget gethttp = new HttpGet ("");HttpGet gethttp =NewHttpGet (""); String content=NULL; BufferedWriter writer=NULL;        HttpResponse response; Try{Response=Httpclient.execute (gethttp); Httpentity Entity=response.getentity (); if(entity!=NULL) {content= Entityutils.tostring (Entity,charset.forname ("GBK"));                SYSTEM.OUT.PRINTLN (content); File File=NewFile ("d:\\baidu.html"); Writer=NewBufferedWriter (NewFileWriter (file));                Writer.write (content);                Writer.flush ();                Writer.close (); System.out.println ("Created successfully"); }        }Catch(Exception e) {//Todo:handle Exception        }    }    }

Two jar packages required I'll post them back.


Small examples of reptiles

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: 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.