PeakGen
PeakGen

Reputation: 23035

Unable to write to the Internal Storage

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.

Upvotes: 0

Views: 1394

Answers (2)

blalasaadri
blalasaadri

Reputation: 6218

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

Upvotes: 1

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

Upvotes: 3

Related Questions