码迷,mamicode.com
首页 > 其他好文 > 详细

网络编程通过输入输出流下载图片

时间:2019-01-17 01:15:36      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:.com   throws   open   new   下载   ring   []   on()   complete   

/**
 * 
 */
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!");
		
	}

}

  

网络编程通过输入输出流下载图片

标签:.com   throws   open   new   下载   ring   []   on()   complete   

原文地址:https://www.cnblogs.com/archer-wen/p/10280173.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!