Ken
Ken

Reputation: 31161

Android external write permitted but file not found exception

In the emulator I'm trying to write to the file:

/mnt/sdcard/Android/data/com.Me.MyApp/files/myFile.txt

I have set external write permissions in the Manifest, but I keep receiving a file not found exception. The emulator is configured to have an sd-card.

Why might that be?

InputStream is = c.getResources().openRawResource(R.raw.my_raw_file);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is));

try
{
  while (zis.getNextEntry() != null)
  {
    File destFile = new File(destinationPath);
    // EXCEPTION THROWN NEXT LINE!
    OutputStream os = new FileOutputStream(destFile);

    byte[] buffer = new byte[BUF_SIZE];
    int count;
    while ((count = zis.read(buffer)) != -1)
    {
      os.write(buffer, 0, count);
    }
  }
}
catch (IOException e)
{
  e.printStackTrace();
}

try
{
  zis.close();
}
catch (IOException e)
{
  e.printStackTrace();
}

Upvotes: 1

Views: 1536

Answers (2)

Dan Dar3
Dan Dar3

Reputation: 1199

Nammari's answer plus:

Android Tutorial: Creating and Using an SD Card in the Emulator
http://www.streamhead.com/android-tutorial-sd-card/

Upvotes: 1

ingsaurabh
ingsaurabh

Reputation: 15269

Try below code

String path = "/mnt/sdcard/Android/data/com.Me.MyApp/files";

File mFile = new File(path);
mFile.mkdirs();

Upvotes: 3

Related Questions