本文实例讲述了Android实现内存中数据保存到sdcard的方法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
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程序设计有所帮助。