Get the network image (Bitmap) to the memory or SD card,
/*** Get the network image ** Note: * <uses-permission android: name = "android. permission. INTERNET "/> */private Bitmap getBitmapFromNetWork (String imageUrl) {URL = null; Bitmap bitmap = null; InputStream inputStream = null; HttpURLConnection httpURLConnection = null; ByteArrayOutputStream byteArrayOutputStream = null; try {url = new URL (imageUrl); httpURLConnection = (HttpURLConnection) url. openConnection (); httpURLConnection. setCon NectTimeout (5*1000); httpURLConnection. setReadTimeout (10*1000); httpURLConnection. setDoInput (true); httpURLConnection. setDoOutput (true); if (httpURLConnection. getResponseCode () = HttpStatus. SC _ OK) {inputStream = httpURLConnection. getInputStream (); byteArrayOutputStream = new ByteArrayOutputStream (); int len = 0; byte [] buffer = new byte [1024]; while (len = inputStream. read (buffer ))! =-1) {byteArrayOutputStream. write (buffer, 0, len); byteArrayOutputStream. flush ();} byte [] imageData = byteArrayOutputStream. toByteArray (); bitmap = BitmapFactory. decodeByteArray (imageData, 0, imageData. length);} else {System. out. println ("image request failed") ;}} catch (Exception e) {System. out. println ("e =" + e. toString ();} finally {try {if (byteArrayOutputStream! = Null) {byteArrayOutputStream. close () ;}if (inputStream! = Null) {inputStream. close ();} if (httpURLConnection! = Null) {httpURLConnection. disconnect () ;}} catch (Exception e) {System. out. println ("e =" + e. toString () ;}} return bitmap;}/*** get the network image and save it to SDCard * Note: * <uses-permission android: name = "android. permission. INTERNET "/> * <uses-permission android: name =" android. permission. WRITE_EXTERNAL_STORAGE "/> */private void getBitmapFromNetWorkAndSaveToSDCard (String imageUrl, String filePath) {URL url = null; File imageFi Le = null; HttpURLConnection httpURLConnection = null; FileOutputStream fileOutputStream = null; bytes = null; InputStream inputStream = null; BufferedInputStream bufferedInputStream = null; try {url = new URL (imageUrl ); httpURLConnection = (HttpURLConnection) url. openConnection (); httpURLConnection. setConnectTimeout (5*1000); httpURLConnection. setReadTimeout (10*1000); httpURLConnection. s EtDoInput (true); httpURLConnection. setDoOutput (true); if (httpURLConnection. getResponseCode () = HttpStatus. SC _ OK) {imageFile = new File (filePath); if (! ImageFile. getParentFile (). exists () {imageFile. getParentFile (). mkdirs () ;}if (! ImageFile. exists () {imageFile. createNewFile ();} fileOutputStream = new FileOutputStream (imageFile); bufferedOutputStream = new BufferedOutputStream (fileOutputStream); inputStream = httpURLConnection. getInputStream (); bufferedInputStream = new BufferedInputStream (inputStream); int len = 0; byte [] buffer = new byte [1024]; while (len = bufferedInputStream. read (buffer ))! =-1) {bufferedOutputStream. write (buffer, 0, len); bufferedOutputStream. flush () ;}} else {System. out. println ("image request failed") ;}} catch (Exception e) {System. out. println ("e =" + e. toString ();} finally {try {if (fileOutputStream! = Null) {fileOutputStream. close ();} if (bufferedOutputStream! = Null) {bufferedOutputStream. close () ;}if (inputStream! = Null) {inputStream. close ();} if (bufferedInputStream! = Null) {bufferedInputStream. close () ;}if (httpURLConnection! = Null) {httpURLConnection. disconnect () ;}} catch (Exception e) {System. out. println ("e =" + e. toString ());}}}