Reputation: 53
I would like to store a file on the SD card. According to the Android docs, SharedPreference
can help to retrieve key-value pairs of primitive data types. However, it stores files in the internal storage.
Is there a class with similar functionality to SharedPreference
but which can store a file on the SD card?
Upvotes: 0
Views: 1364
Reputation: 915
You first need to check if the SD card is accessable with:
File sdDir = Environment.getExternalStorageDirectory();
Do not forget to put below in your Manifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
You can then use something like this:
File file = new File(root, "/sdcard/test.txt");
FileWriter fwriter = new FileWriter(file);
BufferedWriter out = new BufferedWriter(fwriter);
out.write("Hello world");
out.close();
Upvotes: 2