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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:14:33+00:00 2026-05-23T10:14:33+00:00

I have following question. I’d like to place a file named data.xml into sdcard/appname

  • 0

I have following question. I’d like to place a file named data.xml into sdcard/appname folder and use it for read and write application data.

So, when my main activity creates I need to check if this file exist:

public class appname extends ListActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      setContentView(R.layout.no_elements_l);

      File file = getBaseContext().getFileStreamPath("/sdcard/appname/data.xml");
      if(file.exists()) { 

            return;

      } else {

            // create a File object for the parent directory
            File MTdirectory = new File("/sdcard/appname/");

            // have the object build the directory structure, if needed.
            MTdirectory.mkdirs();

            // create a File object for the output file
            File outputFile = new File(MTdirectory, "data.xml");

            // now attach the OutputStream to the file object, instead of a String representation
            FileOutputStream DataFile = new FileOutputStream(outputFile);
      }

But I have Unhandled exception type FileNotFoundException in last line. What’s the problem? Uses permission WRITE_EXTERNAL_STORAGE is added to manifest.

  • 1 1 Answer
  • 1 View
  • 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-23T10:14:34+00:00Added an answer on May 23, 2026 at 10:14 am

    Does the path ‘/sdcard/appname’ exist? You check for the file before you check for the sub-directory ‘appname’. You need to check if that exists before you try to access a file inside it.

    Also if you simply need the file to read-write application data why not just go with internal storage – one less manifest permission 🙂 -> read here for internal storage

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

Sidebar

Related Questions

Good day all I have the following question: I would like to use Chart
i have the following question: I have a XML file with some elements that
I have the following question: I have data frame which looks like this. I
Dear g++ hackers, I have the following question. When some data of an object
I have the following question: If asked whether to use a shift vs a
I have the following question regarding Flex/AIR data grids: Can I access the value
I have started to learn Maven and have the following question: I would like
I have the following question regarding C file I/O. At a physical level (harddrive),
I have a following question. We use log4j in our two projects, that are
I have the following question: This is my main file index.php . <?php class

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.