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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:39:28+00:00 2026-06-08T13:39:28+00:00

I want to check in the android internal storage if new.xml exists(which will be

  • 0

I want to check in the android internal storage if new.xml exists(which will be created by me) then it should return me a handle for it and i may be easily able to append new data to it.If it doesn’t exists create a new one and add data to it.

My xml file structure will be simple like this.

<root>
    <record>a</record>
    <record>b</record>
    <record>c</record>
</root>

If the file is there I will only add a new record to it.But if doesn’t than I will create a new file and add the first record to it.

And How I will be able to read this data in an arraylist. An example with code would be great thanks in advance.

  • 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-08T13:39:29+00:00Added an answer on June 8, 2026 at 1:39 pm

    It’s rather simple. This will help you:

    String filename = "file.txt";
    
    FileOutputStream fos;
    fos = openFileOutput(filename,Context.MODE_APPEND);
    
    XmlSerializer serializer = Xml.newSerializer();
    serializer.setOutput(fos, "UTF-8");
    serializer.startDocument(null, Boolean.valueOf(true));
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    
    serializer.startTag(null, "root");
    
    for(int j = 0; j < 3; j++)
    {
        serializer.startTag(null, "record");
        serializer.text(data);
        serializer.endTag(null, "record");
    }
    
    serializer.endDocument();
    serializer.flush();
    
    fos.close();
    

    To read back data using DOM parser:

    FileInputStream fis = null;
    InputStreamReader isr = null;
    
    fis = context.openFileInput(filename);
    isr = new InputStreamReader(fis);
    
    char[] inputBuffer = new char[fis.available()];
    isr.read(inputBuffer);
    
    data = new String(inputBuffer);
    
    isr.close();
    fis.close();
    
    /*
    * Converting the String data to XML format so
    * that the DOM parser understands it as an XML input.
    */
    
    InputStream is = new ByteArrayInputStream(data.getBytes("UTF-8"));
    ArrayList<XmlData> xmlDataList = new ArrayList<XmlData>();
    
    XmlData xmlDataObj;
    DocumentBuilderFactory dbf;
    DocumentBuilder db;
    NodeList items = null;
    Document dom;
    
    dbf = DocumentBuilderFactory.newInstance();
    db = dbf.newDocumentBuilder();
    dom = db.parse(is);
    
    // Normalize the document
    dom.getDocumentElement().normalize();
    
    items = dom.getElementsByTagName("record");
    ArrayList<String> arr = new ArrayList<String>();
    
    for (int i = 0; i < items.getLength(); i++)
    {
        Node item = items.item(i);
        arr.add(item.getNodeValue());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to check whether a given file exists in android sd card. I
I have created a Android application using Google Maps. Now I want to check
I'm writing simple filter in Android and want to use ExpandableListAdapter with check boxes.
I don't want check if an item with a value exists in the arraylist,
I want to check which port is used, when the port is not explicitly
I want to check a particular file exist in Azure Blob Storage. Is it
I want to check in using facebook android sdk (graph api), I am trying
I have created a database for my android app which contains static data and
In my android application i want to make a feedback dialog that will show
I'm starting to work on Android with the NDK and I want to 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.