java.net.URL的简单使用

来源:互联网 发布:淘宝公告 编辑:程序博客网 时间:2024/06/15 17:11

java.net.URL的简单使用

    博客分类: 
  • java
.netJavaITeyeBlog 
Java代码  收藏代码
  1. import java.io.ByteArrayOutputStream;  
  2. import java.io.IOException;  
  3. import java.io.InputStream;  
  4. import java.net.URL;  
  5. import java.net.URLConnection;  
  6.   
  7. public class UseUrl {  
  8.   
  9.     public static void main(String args[]) throws IOException {  
  10.   
  11.         URL url = new URL("http://234390216.iteye.com/blog/1049256");  
  12.         URLConnection conn = url.openConnection();  
  13.         InputStream is = conn.getInputStream();  
  14.         ByteArrayOutputStream out = new ByteArrayOutputStream();  
  15.         byte[] b = new byte[1024];  
  16.         int len = 0;  
  17.         while ((len = is.read(b)) != -1) {  
  18.             out.write(b, 0, len);  
  19.         }  
  20.         String result = out.toString("UTF-8");  
  21.         out.close();  
  22.         is.close();  
  23.         System.out.println(result);  
  24.     }  
  25.   
  26. }  
0 0
原创粉丝点击