首页 > Web开发 > 详细

根据链接获取网页内容

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

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;
        }
    }

根据链接获取网页内容

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!