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 8893309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:12:51+00:00 2026-06-14T23:12:51+00:00

This is my first question here. I’ve searched for my doubt. I found similar

  • 0

This is my first question here. I’ve searched for my doubt. I found similar questions but i haven’t exactly got my answer. So please forgive me if i have done something wrong.
I’m trying to save an image from an ImageView in my app to a folder in my sdcard. Here’s the code :-

public void save(View view) {
    myImage.setDrawingCacheEnabled(true);
    Bitmap imgV = myImage.getDrawingCache();
    String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + "/AVP_saved");
    String fname="Image.png";
    File file = new File(myDir, fname);
        try {
               FileOutputStream out = new FileOutputStream(file);
               imgV.compress(Bitmap.CompressFormat.PNG, 90, out);
               out.flush();
               out.close();
               Toast.makeText(this, "Image Downloaded", 7000).show();

        } catch (Exception e) {
               e.printStackTrace();
               Toast.makeText(this, e.getMessage(), 8000).show();
        }
    }

‘save’ method is the method assigned to a button. ‘myImage’ is the ImageView found by its id. I have already set the permissions in the manifest. The thing is, the image dosen’t get saved and it says that the path dosen’t exist. When I myself create the folder “AVP_saved”, then the image gets saved. What do i have to edit in this code such that the app creates the folder by itself when i click the button?

Thanks for your time!

  • 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-06-14T23:12:52+00:00Added an answer on June 14, 2026 at 11:12 pm

    Add this code after File myDir = new File(root + "/AVP_saved");

    if(!myDir.exists()) {
      mydir.mkdir(); //you can else call mkdirs() if you have to create a complete directory hierarchy
    }
    

    It seems that in Java, it’s not possible to create a directory hierarchy by creating just a file in it.
    With this, you’ll create your directory only if it doesn’t exist (be careful, if the directory exists but it’s a file, it will launch an exception maybe, so you can look for myDir.isDirectory() too).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first question here but I'm sure there are many more to
This is my first question here, probably a very simple one but I can't
This is my first question that I haven't been able to find an answer
This is my first question on here so here goes.... I've got an issue
This is my first question here, but I hope I will get a lot
this is my first question here; hope I'll be clear enough... I've got this
This is my first question here, and the first time I haven't been able
This is my first question here. I've been researching a lot about this but
this is my first question here so be gentle ! recently i try to
this is my first question here :) I know that I should not check

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.