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();
}