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

  • Home
  • SEARCH
  • 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 6770427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:18:39+00:00 2026-05-26T15:18:39+00:00

I am not able to write to the SDCARD. I can not create a

  • 0

I am not able to write to the SDCARD. I can not create a Directory or a File, what am I missing I have this in the manifest

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

And this in my code

btnSave.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View arg0) 
            {   
                // Create a directory; all ancestor directories must exist
                    boolean success = (new File("/sdcard/Methods/")).mkdirs();
                //create file   
                    try{
                    File myFile = new File("/sdcard/Methods/Method 1 Square.xml");
                    File file = myFile;
                        // Create file if it does not exist
                        boolean success1 = file.createNewFile();}   
                    catch (IOException e) 
                        {}
                //write to file
                    try {
                        BufferedWriter out = new BufferedWriter(new FileWriter("/sdcard/Methods/Method 1 Square.xml"));
                        out.write ("<?xml version=\"1.0\"?>");
                        out.write ("<?mso-application progid=\"Excel.Sheet\"?>");
                        out.write ("Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"");
                        out.close();
                    } // end try
                    catch (IOException e) 
                    {
                    } // end catch

            } // end public

        }); // end SAVE Button
  • 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-26T15:18:40+00:00Added an answer on May 26, 2026 at 3:18 pm

    1st Thing:

    Just check the ‘success’ variable, whether it returns really true.

    2nd Thing:

    As you have hard coded the /sdcard, Instead i suggest you get the directory using: Environment.getExternalStorageDirectory() because in some devices the sd-card root directory is /mnt/sdcard so the above method to get root directory.

    3rd Thing:

    You should first check whether the SD-card is mounted or not.

    Example:

    File sdCard = Environment.getExternalStorageDirectory();
    File dir = new File (sdcard.getAbsolutePath() + "/dir/subdir");  // in your case, just give /Methods
    
    dir.mkdirs();
    File file = new File(dir, "filename");  // in your case, just give "Method 1 Square.xml"
    
    FileOutputStream f = new FileOutputStream(file);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE Added <uses-permission android:name=android.permission.WRITE_EXTERNAL_STORAGE /> to the manifest all works ok now. Ok so
I am not able to figure out this simple thing in ASP.NET MVC: I
My issue is not able to render the chart in .tpl file. The following
I am not able to make a clear decision on this one. I am
I need to write entire Logcat in to sdcard not the filtered Logcat. So
I want to write text file using PHP. I can write it using fopen
I am trying to create an application that is able to write text into
I want to grep a HTTP access log, but I'm not able to write
I need to write data in to a file ,when system reboots not on
I am not able to access localhost https pages in firefox3. It gave the

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.