Here you can find the source of getNetBitmap(String strUrl, File file, Context context, File file2)
public static boolean getNetBitmap(String strUrl, File file, Context context, File file2)
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.util.Log; public class Main { private static final String TAG = "BtimapUtil"; public static boolean getNetBitmap(String strUrl, File file, Context context, File file2) { Log.e(TAG, "getBitmap from net"); Bitmap bitmap = null;/* www . j a va 2 s. c o m*/ InputStream in = null; FileOutputStream out = null; try { URL url = new URL(strUrl); HttpURLConnection con = (HttpURLConnection) url .openConnection(); con.setDoInput(true); con.connect(); in = con.getInputStream(); bitmap = BitmapFactory.decodeStream(in); out = new FileOutputStream(file.getPath()); bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); file.renameTo(file2); out.flush(); } catch (MalformedURLException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } finally { try { if (null != out) { out.close(); } if (null != in) { in.close(); } } catch (IOException e) { e.printStackTrace(); } } return true; } }