日志文章

2007年12月27日 09:57:23

快速读取网页内容


    /*
    * UrlUtil.java
    *
    * Created on 2006年9月27日, 下午5:01
    *
    * To change this template, choose Tools | Options and locate the template under
    * the Source Creation and Management node. Right-click the template and choose
    * Open. You can then make changes to the template in the Source Editor.
    */

   
   import java.io.*;
   import java.util.*;
   import java.net.*;
   /**
    *
    * @author www.tot.name
    */
   public class UrlUtil {
    /** Creates a new instance of UrlUtil */
    public UrlUtil() {
    }
    public static String readHtml(String pageurl){
    StringBuffer sb=new StringBuffer(512);
    URL url= null;
    InputStream is=null;
    BufferedReader br=null;
    try{
    url=new URL(pageurl);
    } catch ( MalformedURLException e) {
    }
    try {
    String fileline=null;
    is = url.openStream();
    InputStreamReader read =new InputStreamReader(is,"GBK");
    br=new BufferedReader(read);
    while ((fileline = br.readLine()) != null) {
    sb.append(fileline+"\n");
    }
    } catch (IOException e) {
    // log.error(e.getMessage());
    } finally{
    try{
    br.close();
    } catch(IOException e){
    e.printStackTrace();
    }
    }
    return sb.toString();
    }


public static void main(String[] args) {
       System.out.println(UrlUtil.readHtml("http://zhangxinzhou.blog.ccidnet.com"));
   }
}

类别: 无分类 |  评论(1) |  浏览(2920) |  收藏
发表评论