I am using this method, found in a lot of questions here in SO:
public void generateNoteOnSD(Context context, String sFileName, String sBody) {
try {
File root = new File(Environment.getExternalStorageDirectory()+File.separator+"folder", "AGL");
if (!root.exists()) {
root.mkdirs();
}
File gpxfile = new File(root, sFileName);
FileWriter writer = new FileWriter(gpxfile);
writer.append(sBody);
writer.flush();
writer.close();
if(gpxfile.exists()){
Toast.makeText(context, "OK", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(context, "KO", Toast.LENGTH_SHORT).show();
}
Almacen.setRutaFichero(gpxfile.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
}
I have this in my AndroidManifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Everything seems to be ok, no exception is thrown, the right Toast is shown in screen...but I go to the folder where the file should be...and its not there. And I am scratching my head, because this very method worked ok a couple of times! I am using a library that writes logs and all...and the files with the logs are there...
Any help?