Skip to content Skip to sidebar Skip to footer

Write A File In Sdcard In Android

I have been searching this problem. It actually worked in older version of android, but after I updated SDK, I get an error. Error message is 'open filed: ENOTDIR (Not a directory)

Solution 1:

This should work, assuming that you have the correct permission in your manifest:

FileexternalStorageDir= Environment.getExternalStorageDirectory();
FileplayNumbersDir=newFile(externalStorageDir, "PlayNumbers");
FilemyFile=newFile(playNumbersDir, "mysdfile.xml");

if (!playNumbersDir.exists()) {
    playNumbersDir.mkdirs();
}
if(!myFile.exists()){
    myFile.createNewFile();
}

Solution 2:

you just need to change to the following code because you missing "/":

myFile = new File(path,"/mysdfile.xml");

But keep in mind that you have to have the permission for writing in external storage in your manifest file :

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

Post a Comment for "Write A File In Sdcard In Android"