leign

Contact: Email: leign.du@gmail.com MSN: dujiali1987@msn.cn
<2011年9月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

统计

  • 随笔 - 12
  • 文章 - 12
  • 评论 - 8
  • 引用 - 0

常用链接

留言簿

随笔档案

文章分类

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜

JAVA获得指定URL网页内容
 1import java.io.*;
 2import java.net.*;
 3
 4public class GetUrlContent {
 5
 6    /**
 7     * 描述:
 8     * @param args
 9     */

10    public static void main(String[] args) {
11        // TODO Auto-generated method stub
12        
13        InputStream in = null;
14        OutputStream out = null;
15        
16        String urlStr = "http://www.baidu.com";
17        String fileStr = "d:\\index.html";
18        
19        try {
20            URL url = new URL(urlStr);
21            
22            in = url.openStream();
23            out = new FileOutputStream(fileStr);
24//            out = System.out;
25            
26            byte[] buffer = new byte[4096];
27            int read;
28            while((read = in.read(buffer)) != -1)
29            {
30                out.write(buffer,0,read);
31//                System.out.print("\n");
32            }

33        }
 catch (Exception e) {
34            // TODO: handle exception
35        }

36        finally
37        {
38            try
39            {
40                in.close();
41                out.close();                
42            }
catch(Exception e1){}
43        }

44    }

45
46}

posted on 2009-11-04 21:02 leign 阅读(751) 评论(1)  编辑 收藏 引用

评论

# re: JAVA获得指定URL网页内容 2011-09-23 20:15 90后非主流

in = url.openStream();
23 out = new FileOutputStream(fileStr);
24// out = System.out;
  回复  更多评论    

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理