Android XML file doesn't save
Posted
by
Shane
on Stack Overflow
See other posts from Stack Overflow
or by Shane
Published on 2012-07-11T02:44:07Z
Indexed on
2012/07/11
3:15 UTC
Read the original article
Hit count: 230
I'm writing a game with LibGDX, and I'm trying to save an XML file, but there's always an exception (java.io.FileNotFoundException: /data/Slugfest/teams/Team1.xml: open failed: ENOENT (No such file or directory)) when saving the file. This code saves the file.
public void save() {
try {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result;
if (Gdx.app.getType() == ApplicationType.Android) {
result = new StreamResult(new File("/data/Slugfest/teams/" + name + ".xml"));
} else {
result = new StreamResult(new File(name + ".xml"));
}
transformer.transform(source, result);
Gdx.app.log("Slugfest", "File saved.");
} catch (TransformerException tfe) {
Gdx.app.log("Slugfest", tfe.getLocalizedMessage());
}
}
My manifest file includes the WRITE/READ_EXTERNAL_STORAGE permissions, by the way.
© Stack Overflow or respective owner