-2

In my application, while writing a file sdcard it shows Permission denied. But i give permission in sdcard. Please help?

Writing file code:

 File sdcard = Environment.getExternalStorageDirectory();
            File f = new File(sdcard, "/abc.txt");
            if (f.exists()) {
                f.delete();
            }


Manifest :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Thanks in advance!!

ρяσѕρєя K
  • 130,641
  • 51
  • 193
  • 212
info
  • 2,102
  • 5
  • 22
  • 38

4 Answers4

0

it requires permissions in manifest file, add this line to your manifest file

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

Look at this Question Android saving file to external storage

Community
  • 1
  • 1
RajaReddy PolamReddy
  • 22,160
  • 18
  • 112
  • 166
0

You need add use-permission in AndroidManifest file, and you should better check if you can r/w the file use canWrite() canRead() before use it.

A.I.
  • 56
  • 3
0

in menifest file add permission to write file

pls try with file name as below

     String filename="aa.txt";
String filepath= getFilesDir().getAbsolutePath();
    File Filseting = new File(filepath, filename);
Ankitkumar Makwana
  • 3,724
  • 3
  • 18
  • 45
0

I think your SD card is currently connect to your computer so it will cause problem. I get in this situation before. You need to unmount sd card first

user1417127
  • 1,495
  • 1
  • 21
  • 29