AnasBakez
AnasBakez

Reputation: 1230

Permission denied Exception when creating new file

i want to create new file iam using this code

try { 
            File file = new File(Environment.getExternalStorageDirectory() + File.separator + "Contacts.vcf");
            file.createNewFile();

         } catch (IOException ioe) 
          {ioe.printStackTrace();}

and using this permission

<permission android:name="android.permission.MOUNT_FORMAT_FILESYSTEMS" ></permission>

but it keeps givinh me exeption that says Permission denied

Upvotes: 1

Views: 1276

Answers (4)

user1087919
user1087919

Reputation:

add this permission into your manifest file

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

Upvotes: 1

Imran Rana
Imran Rana

Reputation: 11909

Give WRITE_EXTERNAL_STORAGE permission to your AndroidManifest file as shown below:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
.........
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

Upvotes: 0

Samir Mangroliya
Samir Mangroliya

Reputation: 40426

when you write any file in External Storage(SD CARD) or Internal Storage ,You have to add permission in manifest file...

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

Upvotes: 2

Jackson Chengalai
Jackson Chengalai

Reputation: 3937

you need to use this permission in manifest file

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

Upvotes: 4

Related Questions