PackageCom.textPa.two;ImportJava.io.BufferedWriter;ImportJava.io.File;ImportJava.io.FileWriter;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 ("http://www.baidu.com");HttpGet gethttp =NewHttpGet ("http://club.news.sohu.com/zz0578/thread/4bqnexpi3no"); 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.
Http://pan.baidu.com/s/1nuFuDUL
Small examples of reptiles