XML file won't update on sdcard



I am trying to read and write XML data from a file on the sdcard, but i can't seem to get it to ever write to the file. It gets read correctly, and when I get a string result from the transformer, I see that I get the correct result, but the xml file ever gets updated. I don't get any exceptions, I simply cannot get the file to write.



String path = Environment.getExternalStorageDirectory().toString() + "/m_cubed/settings.xml";
File settingsFile = new File(path);

Document doc = DocumentBuilderFactory
.newInstance()
.newDocumentBuilder()
.parse(settingsFile);

Node themeNode = doc.getElementsByTagName("theme").item(0);
themeNode.setTextContent(theme);

Transformer transformer = TransformerFactory.newInstance().newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File(path));
transformer.transform(source, result);


Looking at many other similar issues here, the main problem seems to be the use of setNodeValue instead of setTextContent, but as you can see this is not my case. It also seems like using a normal FileOutputStream also does not update the file. So what am I doing wrong?


EDIT It seems that if I write to a different file in the same directory, I will get that new file with the correct contents. So how do I get it to write to the same file being used by the Document?


No comments:

Post a Comment