[英]Android: Can't find generated XML file
I am working on a method that writes an XML file to the device. 我正在研究一种将XML文件写入设备的方法。 I've allowed external storage in the manifest file, but I can't find the file at the location it should be. 我已允许在清单文件中进行外部存储,但找不到文件应位于的位置。
Here is my code: 这是我的代码:
public static void write (){
Serializer serial = new Persister();
File sdcardFile = new File("/Prueba/file.xml");
Item respuestas = new Item();
try {
serial.write(respuestas, sdcardFile);
} catch (Exception e) {
// There is the possibility of error for a number of reasons. Handle this appropriately in your code
e.printStackTrace();
}
Log.i(TAG, "XML Written to File: " + sdcardFile.getAbsolutePath());
}
}
Sdcard File path problem. sdcard文件路径问题。 Here is an exaple that write string in file.xml file. 这是在file.xml文件中写入字符串的示例。
File myFile = new File("/sdcard/file.xml");
try {
File myFile = new File("/sdcard/file.xml");
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter =
new OutputStreamWriter(fOut);
myOutWriter.append("encodedString");
myOutWriter.close();
fOut.close();
} catch (Exception e) {
}
You able to get External Storage name by this way, 您可以通过这种方式获取外部存储名称,
String root = Environment.getExternalStorageDirectory().toString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.