Home » Android » android – Best way to download image from URL and save it into internal storage memory

android – Best way to download image from URL and save it into internal storage memory

Posted by: admin June 15, 2020 Leave a comment


I am developing an app in which I want to download image from URL. I need to download these images at once and stored it into internal storage. There are more than 200 images for downloading. Please tell me the best way to download these images at minimum time possible. If any third part library is available the please tell.

How to&Answers:

Consider using Picasso for your purpose. I’m using it in one of my project. To save image on external disk you can use following:

        .into(new Target() {
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                try {
                    String root = Environment.getExternalStorageDirectory().toString();
                    File myDir = new File(root + "/yourDirectory");

                    if (!myDir.exists()) {

                    String name = new Date().toString() + ".jpg";
                    myDir = new File(myDir, name);
                    FileOutputStream out = new FileOutputStream(myDir);
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);

                } catch(Exception e){
                    // some action

            public void onBitmapFailed(Drawable errorDrawable) {

            public void onPrepareLoad(Drawable placeHolderDrawable) {

From here you can download this library.


You can download th image from an url like this:

URL url = new URL("http://www.yahoo.com/image_to_read.jpg");
InputStream in = new BufferedInputStream(url.openStream());
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int n = 0;
while (-1!=(n=in.read(buf)))
   out.write(buf, 0, n);
byte[] response = out.toByteArray();

And you may then want to save the image so do:

FileOutputStream fos = new FileOutputStream("C://borrowed_image.jpg");