码迷,mamicode.com
首页 > 编程语言 > 详细

java读取网页

时间:2015-09-09 21:27:17      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

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();
            

    }

}

 

java读取网页

标签:

原文地址:http://www.cnblogs.com/zywf/p/4795920.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!