The problem is that I put the file through the DDMS Perspective in data and /data/data folder and when I try to access to that files, the FileNotFoundException occures. Code:
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();
}
Exception with print:
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)
I've tried also:
String path = Environment.getExternalStorageState()+"/data/analyzer_settings.xml";
or
String path = Environment.getExternalStorageState()+"/data/data/analyzer_settings.xml";
nothing worked for me.
use
String path = Environment.getExternalStorageDirectory().getAbsolutePath()
+"analyzer_settings.xml";
instead of
String path = Environment.getExternalStorageState()+"/analyzer_settings.xml";
getExternalStorageDirectory ():
Gets the Android external storage directory. This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened. You can determine its current state with getExternalStorageState().
and
Gets the current state of the primary "external" storage device.