1

So I call this method within my MainActivity..

public void CreateXMLFile() throws ParserConfigurationException, TransformerException {

    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    Document doc = docBuilder.newDocument();
    Element rootElement = doc.createElement("user");
    doc.appendChild(rootElement);

    Element name = doc.createElement("name");
    rootElement.appendChild(name);

    Element displayInstructions = doc.createElement("displayInstructions");
    rootElement.appendChild(displayInstructions);

    Element scores = doc.createElement("scores");
    rootElement.appendChild(scores);

    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    DOMSource source = new DOMSource(doc);
    StreamResult result = new StreamResult(new File(context.getFilesDir(), "info.xml"));
    transformer.transform(source, result);
}

The problem is.. i dont actually know if it's being created. Is there any way to check?

1
  • do u want to check if info.xml is created? Commented Dec 6, 2016 at 3:51

1 Answer 1

1

if you want to check if the file is created or not, you can do something like below

File file = new File(this.getFilesDir(), "info.xml");
if (file.exists()) {
    //Do something
    Log.d("","file is available");
} else {
    // Do something else.
    Log.d("","file is not available");
}

Above code will check if the file exists or not.

Please note that this is based on my understanding on the limited information you have given on your problem.

Sign up to request clarification or add additional context in comments.

1 Comment

You can use this approach on non-rooted phone. If you have a rooted phone, you can navigate directly to the directory via file manager/explorer and check the file there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.