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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:14:03+00:00 2026-05-26T12:14:03+00:00

I have a little issue with creating a directory and saving a file to

  • 0

I have a little issue with creating a directory and saving a file to it on my android application. I’m using this piece of code to do this :

String filename = "MyApp/MediaTag/MediaTag-"+objectId+".png";
File file = new File(Environment.getExternalStorageDirectory(), filename);
FileOutputStream fos;

fos = new FileOutputStream(file);
fos.write(mediaTagBuffer);
fos.flush();
fos.close();

But it’s throwing an exception :

java.io.FileNotFoundException: /mnt/sdcard/MyApp/MediaCard/MediaCard-0.png (No such file or directory)

on that line : fos = new FileOutputStream(file);

If I set the filename to : "MyApp/MediaTag-"+objectId+" it’s working, but If I try to create and save the file to an another directory it’s throwing the exception. So any ideas what I’m doing wrong?

And another question: Is there any way to make my files private in external storage so user can’t see them in gallery, only if he connect his device as Disk Drive?

  • 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-26T12:14:04+00:00Added an answer on May 26, 2026 at 12:14 pm

    Use this function to save your bitmap in SD card

    private void SaveImage(Bitmap finalBitmap) {
    
        String root = Environment.getExternalStorageDirectory().toString();
        File myDir = new File(root + "/saved_images");    
         if (!myDir.exists()) {
                        myDir.mkdirs();
                    }
        Random generator = new Random();
        int n = 10000;
        n = generator.nextInt(n);
        String fname = "Image-"+ n +".jpg";
        File file = new File (myDir, fname);
        if (file.exists ())
          file.delete (); 
        try {
            FileOutputStream out = new FileOutputStream(file);
            finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
            out.flush();
            out.close();
    
        } catch (Exception e) {
             e.printStackTrace();
        }
    }
    

    and add this in manifest

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

    EDIT: By using this line you will be able to see saved images in the gallery view.

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                             Uri.parse("file://" + Environment.getExternalStorageDirectory())));
    

    look at this link also http://rajareddypolam.wordpress.com/?p=3&preview=true

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

Sidebar

Related Questions

I have a little issue concerning an animation-effect which loads a certain div into
Hey guys I have a little issue here. I have a panel where I
I have little question about how web browser retrieve webpage? I know this User
I have little doubt about string reading in C. string reading functions like gets,
I have a very complicated issue, but if I can do this, then I
I am using FluentValidation in my application to verify my entities, but I have
I have an issue that on one computer applications developed using the Windows Presentation
Now this probably seems a little stupid at first, but I am creating a
I have a little issue here. Why does my search bar search when I
I have a little issue right now and its bugging me, hopefully one of

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.