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?
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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.