-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
  • 132,198
  • 53
  • 198
  • 213
info
  • 2,152
  • 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,428
  • 19
  • 115
  • 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,475
  • 3
  • 19
  • 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,525
  • 1
  • 21
  • 29