Here you can find the source of downPicture(String filePath, String imageUrl, String fileName)
public static Map<String, Object> downPicture(String filePath, String imageUrl, String fileName)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.util.HashMap; import java.util.Map; public class Main { public static Map<String, Object> downPicture(String filePath, String imageUrl, String fileName) { Map<String, Object> map = new HashMap<String, Object>(); Integer size = null;//from w w w .j a v a 2 s.com String mime = null; try { File files = new File(filePath); if (!files.exists()) { files.mkdirs(); } URL url = new URL(imageUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); InputStream is = connection.getInputStream(); if (!filePath.endsWith("/")) { filePath = filePath + "/"; } File file = new File(filePath + fileName); FileOutputStream out = new FileOutputStream(file); int i = 0; while ((i = is.read()) != -1) { out.write(i); } size = connection.getContentLength(); mime = connection.getContentType(); is.close(); } catch (Exception e) { } map.put("size", size); map.put("mime", mime); return map; } }