Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7509505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:56:13+00:00 2026-05-29T22:56:13+00:00

I try to download an image with this code and save it : in

  • 0

I try to download an image with this code and save it :
in this line:

OutputStream os =new FileOutputStream(f);

i try it on the emulator.my app get exception that there is no permission to save to this path:

java.io.FileNotFoundException: /mnt/sdcard/InterFlora/1221618532: open failed: EACCES (Permission denied)

i also add this line :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

this is the code:

   RetreiveImage extends AsyncTask<String, Void,Bitmap> {
           Item m_item;
           File f;

           public RetreiveImage(Item aItem , File aFile){
               m_item = aItem;
               f = File (m_Sdcard.getAbsolutePath() + "/myFolder");
           }

        @Override
        protected Bitmap doInBackground(String... params) {

        try
        {
            Bitmap bitmap=null;
            InputStream is=new URL(m_item.small).openStream();
            OutputStream os =new FileOutputStream(f);
            os.close();

            return bitmap;
        }
        catch (MalformedURLException e) {
            return null;
        } catch (IOException e) {
            return null;
        }
    }
}

Edit

File m_Sdcard = Environment.getExternalStorageDirectory();
File cacheDir =new File (m_Sdcard.getAbsolutePath() + "/MyFolder");
if(!cacheDir.exists())
cacheDir.mkdirs();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:56:15+00:00Added an answer on May 29, 2026 at 10:56 pm
     Try this works..
    
     import java.io.BufferedInputStream;
     import java.io.File;
     import java.io.FileOutputStream;
     import java.io.InputStream;
     import java.io.OutputStream;
     import java.net.URL;
     import java.net.URLConnection;
    
     import android.app.Activity;
     import android.app.Dialog;
     import android.app.ProgressDialog;
     import android.content.Context;
     import android.content.Intent;
      import android.net.Uri;
      import android.os.AsyncTask;
      import android.os.Bundle;
      import android.util.Log;
      import android.view.View;
      import android.view.View.OnClickListener;
      import android.widget.Button;
    
      public class main extends Activity {
      /** Called when the activity is first created. */
        public static final int DIALOG_DOWNLOAD_PROGRESS = 0;
        private Button startBtn;
        private ProgressDialog mProgressDialog;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            startBtn = (Button)findViewById(R.id.startBtn);
            startBtn.setOnClickListener(new OnClickListener(){
                public void onClick(View v) {
                    startDownload();
                }
            });
        }
    
        private void startDownload() {
            String url = "http://farm1.static.flickr.com/114/298125983_0e4bf66782_b.jpg";
            new DownloadFileAsync().execute(url);
    
        }
        @Override
        protected Dialog onCreateDialog(int id) {
            switch (id) {
            case DIALOG_DOWNLOAD_PROGRESS:
                mProgressDialog = new ProgressDialog(this);
                mProgressDialog.setMessage("Downloading file..");
                mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                mProgressDialog.setCancelable(false);
                mProgressDialog.show();
                return mProgressDialog;
            default:
                return null;
            }
        }
    
    class DownloadFileAsync extends AsyncTask<String, String, String> {
    
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            showDialog(DIALOG_DOWNLOAD_PROGRESS);
        }
    
        @Override
        protected String doInBackground(String... aurl) {
            int count;
    
        try {
    
        URL url = new URL(aurl[0]);
        URLConnection conexion = url.openConnection();
        conexion.connect();
    
        int lenghtOfFile = conexion.getContentLength();
        Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);
        FileOutputStream obj;
        InputStream input = new BufferedInputStream(url.openStream());
        //obj=openFileOutput("some_photo_from_gdansk_poland.jpg", Context.MODE_PRIVATE);
        String Path="/sdcard/";//"/data/data/com.server/";
    
        OutputStream output = new FileOutputStream(Path+"some_photo_from_gdansk_poland.jpg");//obj
    
        byte data[] = new byte[1024];
    
        long total = 0;
    
            while ((count = input.read(data)) != -1) {
                total += count;
                publishProgress(""+(int)((total*100)/lenghtOfFile));
                output.write(data, 0, count);
            }
    
            output.flush();
            output.close();
            input.close();
        } catch (Exception e) {}
        return null;
    
        }
        protected void onProgressUpdate(String... progress) {
             Log.d("ANDRO_ASYNC",progress[0]);
             mProgressDialog.setProgress(Integer.parseInt(progress[0]));
        }
    
        @Override
        protected void onPostExecute(String unused) {
            dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
        }
    }
    
       }
    
      and add android.permission.WRITE_EXTERNAL_STORAGE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am try to download image files from url from the following code, but
I want to download image from internet :: I refer this and try this
I have some code that retrieves an image from the web using this method
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
Hi I have this code to download images from the server and then to
Can someone please give me a hand with this image downloading code? I want
I have seen this question: android how to download an 1mb image file and
I try to use php to force the image jpg file download, I have
I have a big problem dealing with data I try to download in my
I download and try to install the rpm package for fedora 10, i also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.