09-06
11

远程采集,无乱码

下面是读取csdn中某一页的内容:

  import   java.net.*;  
  import   java.io.*;  
  import   java.util.*;  
  public   class   URLDemo   {  
    
  public   static   void   main(String[]   args)   {  
    
  System.out.println("Starting...");  
  int   c;  
  URLConnection   urlcon=null;  
  //HttpURLConnection   urlcon   =   null;  
  try  
  {  
  URL   url   =   new   URL("http://www.csdn.net");  
        try  
  {  
  urlcon   =   url.openConnection();  
  //urlcon   =   (HttpURLConnection)url.openConnection();  
  }  
  catch   (IOException   e)  
  {  
    
  }  
  System.out.println("the   date   is   :"+new   Date(urlcon.getDate()));  
  System.out.println("content_type   :"+urlcon.getContentType());  
  try  
  {  
  String   webpage;  
  InputStream   in   =   urlcon.getInputStream();  
  while(((   c=in.read())!=-1))  
  {  
  int   all=in.available();  
  byte[]   b   =new   byte[all];  
  in.read(b);  
    
  webpage   =new   String(b,"UTF-8");  
  System.out.println(webpage);  
    
  }  
  in.close();  
    
  }  
  catch(IOException   e)  
  {  
  System.out.println(""+e);  
  }  
    
    
  }  
  catch(MalformedURLException   e)  
  {  
  System.out.println(""+e);  
  }  
    
  }  
    
  }  
    


[本日志由 blurxx 于 2009-06-27 09:26 AM 编辑]
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: 远程 采集 uncode
相关日志:
评论: 0 | 引用: 0 | 查看次数: 192
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭