tags:

views:

3342

answers:

3

I would like my app to archive the application DB to the SD card. In my code I check if the directory canWrite(), and if not then throw an IOException. In this perticular instance, I am trying to copy the db file to the root directory on the SD card, but its throwing an IOException. How can I change the permission on a folder/file to be able to write to it?

thanks

patrick

A: 

Figured out I need to use /sdcard/

+11  A: 

You're right that the SD Card directory is /sdcard but you shouldn't be hard coding it. Instead, make a call to Environment.getExternalStorageDirectory() to get the directory:

File sdDir = Environment.getExternalStorageDirectory();

If you haven't done so already, you will need to give you app the correct permission to write to the SD Card by adding this to your Manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Dave Webb
Thanks...I will change my code as per your suggestion. However currently I have it hard coded, and do not have the permission set in the manifest file but it allows me to save it to the sd card anyway. why am I able to save it wothout having the permission set?
@user244190 - my guess would be that your phone is running Android 1.5. `WRITE_EXTERNAL_STORAGE` was introduced in 1.6, so you'll need to include it in your application if you want it to be forward-compatible.
Dave Webb
gotcha. thanks...
A: 

Thanks a lot Dave Webb. I am now able to create file in the SD Card.

Janardhanan.S