java读取网页

package cn.stat.p4.ipdemo;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

public class iedemo {

    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {

            String url_str="http://www.baidu.com/";
            URL url=new URL(url_str);
            InputStreamReader ins= new InputStreamReader(url.openStream(), "UTF8");
            
            char[] buf=new char[2024];
            
            int len=0;
            while((len=ins.read(buf))!=-1)
            {
            String text=new String(buf,0,len);
            
            System.out.print(text);
            }
            ins.close();
            

    }

}

 

posted @ 2015-09-09 20:48  自由无风  阅读(623)  评论(0编辑  收藏  举报