Here you can find the source of downImg(String filePath, String imageUrl, String fileName)
public static boolean downImg(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.URL; import java.net.URLConnection; public class Main { public static boolean downImg(String filePath, String imageUrl, String fileName) { try {//from w ww . ja v a2 s. c o m File files = new File(filePath); if (!files.exists()) { files.mkdirs(); } URL url = new URL(imageUrl); URLConnection con = url.openConnection(); InputStream is = con.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); } is.close(); return true; } catch (Exception e) { return false; } } }