0

Please have a look at the following code

File folder = new File("/Main Note/Sub Notes/"+dateStr+"/");
File file = new File(folder+name.getText().toString()+".txt");
    try
    {

        if(!folder.exists())
        {
            folder.mkdirs();
        }

        FileOutputStream outputStream =  openFileOutput(file.getName(),Context.MODE_WORLD_WRITEABLE);
        outputStream.write(spokenText.getBytes());
        outputStream.flush();
        outputStream.close();

        Toast.makeText(VoiceNotes.this, "Data Successfully written to: "+file.getAbsolutePath(), Toast.LENGTH_LONG).show();
    }
    catch(IOException io)
    {
        Toast.makeText(VoiceNotes.this, "Error in Writing to SD", Toast.LENGTH_LONG).show();
    }

Here I am trying to write data to the internal memory. This has no errors, displays the data has been written successfully.

But when I navigate to the Internal SD in phone, I don't see any folder or file it created! I guess I have done something wrong, this is the first time I am writing to the internal storage in Android.

halfer
  • 19,824
  • 17
  • 99
  • 186
PeakGen
  • 21,894
  • 86
  • 261
  • 463

2 Answers2

3
File folder = new File(context.getFilesDir(),"/MyFolder/");

files will be created in "/data/data/app.package/files/...". But you can see them only if device was rooted

1

You want to access the path returned by getExternalStorageDirectory() as described here.

blalasaadri
  • 5,990
  • 5
  • 38
  • 58
  • this is for internal, not external – PeakGen Nov 15 '13 at 08:16
  • True, but sadly it is not standardized amongst the Android devices, which SD card is internal and which is external. You will get one of them back but which one depends on your device. If you want to access the internal one in any case, maybe this question will help you: http://stackoverflow.com/questions/17203615/why-is-this-code-incorrectly-reporting-free-space-on-my-android-device – blalasaadri Nov 15 '13 at 08:19