我正在使用 LibGDX 编写游戏,并且正在尝试保存 XML 文件,但总是出现异常(java.io.FileNotFoundException: /data/Slugfest/teams/Team1.xml: open failed: ENOENT (No such文件或目录))保存文件时。此代码保存文件。
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());
}
}
顺便说一句,我的清单文件包含 WRITE/READ_EXTERNAL_STORAGE 权限。