File储存
使用 openFileOutput(文件名,储存方式) 进行储存
private String name ;
try {
FileOutputStream fos = openFileOutput("insert.txt", MODE_APPEND);
String msg = name+",";
fos.write(msg.getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
储存到手机内存中
使用 SharedPreferences 的 getSharedPreferences(文件名 ,储存方式) 方法进行存储
SharedPreferences sp = getSharedPreferences("update", MODE_PRIVATE);
String msg = sp.getString("name","")+name+",";
SharedPreferences.Editor edit = sp.edit();
edit.putString("name",msg);
edit.commit();
储存到SD卡中
SD卡的路径 : Environment.getExternalStorageDirectory()
try {
File file = new File(Environment.getExternalStorageDirectory(), "delete.txt");
String msg = name+",";
FileOutputStream fos = new FileOutputStream(file, true);
fos.write(msg.getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
本文介绍了在Android应用中三种常见的文件存储方法:使用FileOutputStream将数据存入手机内存、利用SharedPreferences保存配置信息,以及通过FileOutputStream将文件写入SD卡。
1239

被折叠的 条评论
为什么被折叠?



