一、存到内部
- 保存到内部
FileOutputStream fos= openFileOutput(file_name, Context.MODE_PRIVATE);
// 当内容需要追加的时候MODE_APPEND
fos.write(file_content.getBytes(“utf-8”)); // 转换成utf-8字节编码 从内部读取文件
FileInputStream fis = openFileInput(file_name);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String msg = “”;
StringBuffer stringBuffer = new StringBuffer();
while ((msg = br.readLine()) != null) {
stringBuffer.append(msg);
}
二、保存数据到sd卡
// 判断sdcard卡是否可用
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
String file_name = et_filename.getText().toString().trim();
String file_content = et_filecontent.getText().toString().trim();
//sd卡的路径
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
try {
FileOutputStream fos = new FileOutputStream(path