I want to store data recorded with the accelerometer on the external storage but I have an error when I try to create the directory in which I want to save the data. My code is as follows :
dataDirectory=Environment.getDataDirectory();
path=DataDirectory.getAbsolutePath();
path+="/"+getResources().getString(R.string.DirectoryName);
myDirectory=new File(path);
myDirectory.createNewFile();
The createNewFile call triggers an IOException.
I can add two things : the path variable is set to “/data” after the call to getAbsolutePath and the getExternalStorageState function returns “mounted”.
Can anyone tell me what is wrong in my code?
Thanks in advance for the time you will spend trying to help me.
You can’t have permission to write in the
/datadirectory/data/data/com.yourapplication/filesdirectory where you do have permission. UseContext.getFilesDir()to get the path of your application’s working directory.