1

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?

Fustigador
  • 6,339
  • 12
  • 59
  • 115

1 Answers1

0

If the "OK" toast displays, the file has already been created successfully. So why can not see the file?

  1. check Almacen.setRutaFichero(gpxfile.getAbsolutePath()); what does the method do?
  2. go to correct file location, in your case it will be:

enter image description here

  1. manually refresh the folder using mouse
navylover
  • 12,383
  • 5
  • 28
  • 41