zoukankan      html  css  js  c++  java
  • 网络编程通过输入输出流下载图片

    /**
     * 
     */
    package itest;
    
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.URL;
    import java.net.URLConnection;
    
    /**
     * @author archer
     *
     */
    public class UrlConnectionTest {
    
    	/**
    	 * @param args
    	 * @throws IOException 
    	 */
    	public static void main(String[] args) throws IOException {
    		// TODO Auto-generated method stub
    		String urlString = "http://bpic.588ku.com/art_origin_min_pic/18/12/02/e0549633966e7115c28631964a8e8b6d.jpg";
    		String path ="E:\Temp\2019.jpg";  
    		int n = -1;
    		URL url = new URL(urlString);
    		URLConnection conn = url.openConnection();
    		//获取输入流
    		InputStream in = conn.getInputStream();
    		//获取输出流
    		OutputStream out = new FileOutputStream(path);
    		//循环读写过程
    		while((n = in.read()) != -1){
    			out.write(n);
    		}
    		in.close();
    		out.close();
    		System.out.println("completed!");
    		
    	}
    
    }
    

      

  • 相关阅读:
    mogodb优化
    uuid
    ssl详解
    探究rh6上mysql5.6的主从、半同步、GTID多线程、SSL认证主从复制
    CMAKE MYSQL
    证书生成
    叶金荣主页
    mysqlslap
    sysbench 测试MYSQL
    mysql实验室
  • 原文地址:https://www.cnblogs.com/archer-wen/p/10280173.html
Copyright © 2011-2022 走看看