本文实例讲述了Android实现内存中数据保存到sdcard的方法。分享给大家供大家参考,具体如下:
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();// 记得关闭
outStream.close();
} catch (Exception e) {
Log.i("test result", "file write error");
e.printStackTrace();
}
}
更多关于Android操作sdcard相关内容感兴趣的读者可查看本站专题:《Android编程开发之SD卡操作方法汇总》
希望本文所述对大家Android程序设计有所帮助。