Android implements the method of storing data in memory to sdcard
- 2021-01-18 06:38:24
- OfStack
This article illustrates how Android implements in-memory data storage to sdcard. To share with you for your reference, as follows:
public static void writeToSdCard(String s) {
try {
File dst = new File("/sdcard/test_sensor/" + mName + ".txt");
File parent = dst.getParentFile();
if(!parent.exists()) {
parent.mkdirs();
}
FileOutputStream outStream = new FileOutputStream(dst, true);
OutputStreamWriter writer = new OutputStreamWriter(outStream, "gb2312");
writer.write(s);
writer.write("\n");
writer.flush();
writer.close();// Remember to close the
outStream.close();
} catch (Exception e) {
Log.i("test result", "file write error");
e.printStackTrace();
}
}
More about Android operation sdcard related content interested readers can see the site special topic: Android programming development SD card operation method summary
I hope this article is helpful to Android program design.