heting

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  40 随笔 :: 9 文章 :: 45 评论 :: 0 Trackbacks
 1public String getOneHtml(String htmlurl, String bianma) throws IOException {
 2        URL url;
 3        String temp;
 4        final StringBuffer sb = new StringBuffer();
 5        StringBuffer sb2 = new StringBuffer();
 6        //因为htmlurl字符串中如果出现空白的字符就会出异常
 7        String [] htmlurls=htmlurl.split(" ");
 8        for (int i = 0; i < htmlurls.length; i++{
 9            if ("".equals(htmlurls[i])) {
10                continue;
11                }

12            sb2.append(htmlurls[i]);
13        }

14        try {
15            url = new URL(sb2.toString());
16            final BufferedReader in = new BufferedReader(new InputStreamReader(
17                    url.openStream(), bianma));
18            while ((temp = in.readLine()) != null{
19                sb.append(temp);
20            }

21            in.close();
22        }
 catch (final MalformedURLException me) {
23            // System.out.println("the url is error");
24            me.getMessage();
25            throw me;
26        }
 catch (final IOException e) {
27            e.printStackTrace();
28            throw e;
29        }

30        return sb.toString();
31    }
posted on 2008-11-08 10:42 贺挺 阅读(156) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: