问题是我通过 DDMS Perspective 将文件放在 data 和 /data/data 文件夹中,当我尝试访问该文件时,会发生 FileNotFoundException。代码:
String path = Environment.getExternalStorageState()+"/analyzer_settings.xml";
System.out.println(path);
try {
Scanner in = new Scanner(new File(path));
while (in.hasNext()) {
System.out.println(in.nextLine());
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
打印例外:
07-11 17:10:02.470: I/System.out(13506): mounted/analyzer_settings.xml
07-11 17:10:02.500: W/System.err(13506): java.io.FileNotFoundException: /mounted/analyzer_settings.xml: open failed: ENOENT (No such file or directory)
我也试过:
String path = Environment.getExternalStorageState()+"/data/analyzer_settings.xml";
or
String path = Environment.getExternalStorageState()+"/data/data/analyzer_settings.xml";
没有什么对我有用。