码迷,mamicode.com
首页 > Web开发 > 详细

根据链接获取网页内容

时间:2014-08-29 12:48:07      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:os   io   sp   line   on   new   ad   c   app   

public static String getContent(String strUrl) throws Exception {
        try {
            URL url = new URL(strUrl);
            BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));
            String s = "";
            StringBuffer sb = new StringBuffer("");
            while ((s = br.readLine()) != null) {
                sb.append(s);
            }

            br.close();
            return sb.toString();
        } catch (Exception e) {
            System.out.println("can‘t open url:"+strUrl);
            throw e;
        }
    }

根据链接获取网页内容

标签:os   io   sp   line   on   new   ad   c   app   

原文地址:http://www.cnblogs.com/IT-shen/p/3944536.html

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