我是Android的初级开发人员,在尝试访问SD卡上的XML文件时遇到以下问题。
首先,我进行了以下检查: - 读取/写入外部存储的权限在android清单中给出 - 该文件存在于指定位置 - 我查了一下:fileexists = true; canread = true; isfile = true - externalstorage state =已挂载
仍然FileInputStream给我FileNoteFoundException。代码:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
//probeersel
public void myClickHandler(View view) {
switch (view.getId()) {
case R.id.button1:
XPath xpath = XPathFactory.newInstance().newXPath();
File mealsource = new File(getExternalFilesDir(null)
+ "/test.xml");
Toast.makeText(this, "External Files Dir: " + getExternalFilesDir(null), Toast.LENGTH_LONG).show();
Toast.makeText(this, "Exists: " + String.valueOf(mealsource.exists()), Toast.LENGTH_LONG).show();
Toast.makeText(this, "Can read: " + String.valueOf(mealsource.canRead()), Toast.LENGTH_LONG).show();
Toast.makeText(this, "Is file: " + String.valueOf(mealsource.isFile()), Toast.LENGTH_LONG).show();
Toast.makeText(this, "External Storage State: " + Environment.getExternalStorageState(), Toast.LENGTH_LONG).show();
Toast.makeText(this, "Absolute path " + mealsource.getAbsolutePath(), Toast.LENGTH_LONG).show();
FileInputStream mealstream = new FileInputStream(mealsource);
InputSource inputsource = new InputSource(mealstream);
expression = "Meals/Meal/ShrtDesc/text()";
meallist = (NodeList) xpath.evaluate(expression, inputsource, XPathConstants.NODE);
etc
所以回顾一下:我的所有检查都说文件是在那里读取并准备好进行操作,但是FileInputStream构造函数似乎对此视而不见。我是什么做的?我错过了什么?它可能与某种程度上的xml内容有关吗?
非常感谢你给我的任何帮助或指示。