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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:27:21+00:00 2026-05-25T02:27:21+00:00

In my android app I try to create a xml file on sdcard. I

  • 0

In my android app I try to create a xml file on sdcard. I tried this :

public class XmlFileCreator extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        System.out.println(Environment.getExternalStorageDirectory());
        // create a new file called "new.xml" in the SD card
        File newxmlfile = new File( Environment.getExternalStorageDirectory(),"new.xml");
        try {
            newxmlfile.createNewFile();
        } catch (IOException e) {
            Log.e("IOException", "exception in createNewFile() method");
        }

        FileOutputStream fileos = null;
        try {
            fileos = new FileOutputStream(newxmlfile);
        } catch (FileNotFoundException e) {
            Log.e("FileNotFoundException", "can't create FileOutputStream");
        }
        // we create a XmlSerializer in order to write xml data
        XmlSerializer serializer = Xml.newSerializer();

        try {
            // we set the FileOutputStream as output for the serializer, using
            // UTF-8 encoding
            serializer.setOutput(fileos, "UTF-8");
            // Write <?xml declaration with encoding (if encoding not null) and
            // standalone flag (if standalone not null)
            serializer.startDocument(null, Boolean.valueOf(true));
            // set indentation option
            serializer.setFeature(
                    "http://xmlpull.org/v1/doc/features.html#indent-output",
                    true);
            // start a tag called "root"
            serializer.startTag(null, "root");
            // i indent code just to have a view similar to xml-tree
            serializer.startTag(null, "child1");
            serializer.endTag(null, "child1");
            serializer.startTag(null, "child2");
            // set an attribute called "attribute" with a "value" for <child2>
            serializer.attribute(null, "attribute", "value");
            serializer.endTag(null, "child2");

            serializer.startTag(null, "child3");
            // write some text inside <child3>
            serializer.text("some text inside child3");
            serializer.endTag(null, "child3");

            serializer.endTag(null, "root");
            serializer.endDocument();
            // write xml data into the FileOutputStream
            serializer.flush();
            // finally we close the file stream
            fileos.close();

            System.out.println("file has been created on SD card");         
        }
        catch(Exception e){
            Log.e("Exception","error occurred while creating xml file");
        }
    }
}

but in LogCat I get this :

08-23 11:19:56.776: ERROR/IOException(6333): exception in createNewFile() method
08-23 11:19:56.776: ERROR/FileNotFoundException(6333): can't create FileOutputStream
08-23 11:19:56.776: ERROR/Exception(6333): error occurred while creating xml file

Where is the problem? Why createNewFile() throws an IOException? Need some help, please…

  • 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-25T02:27:21+00:00Added an answer on May 25, 2026 at 2:27 am

    Once check the manifast file that you mentioned the permission to write in external storage or not

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

Sidebar

Related Questions

i've developed an android app that's fetches an xml file and displays this data
I created a colors.xml file in my Android app under /res/values/colors.xml. The contents are...
I have a class which extends android.app.Application , which I use to persist global
I've got an Android app which has a periodic background Service. I want this
I am trying to create a simple 3-D app for android that will have
Here is my code for my db class: package one.two; import java.util.List; import android.app.ListActivity;
So there is this game im trying to create, and in the lessons activity
A simple android Hello World: MainActivity.java: package com.amaker.ch02.app; import android.app.Activity; import android.os.Bundle; import android.widget.TextView;
i try to create small example to test GPS here package org.example.location; import com.google.android.maps.MapActivity;
I am writing data to xml files in my android app. I looked up

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.