注意 我们是将数据保存到了 ad卡,
外存的地址是在 mnt sdcard 目录下
public class SaveFileService {
// 注意 通过外存存储时数据被放在了 mnt sdcard 目录下
/**
* 存储操作
*
* @param username
* 帐号名
* @param password
* 密码
* @return
*/
public static boolean saveFile(Context context, String username,
String password)
{
String result = Environment.getExternalStorageState();
if(Environment.MEDIA_MOUNTED.equals(result))
{
//注意外存挂起就是外存不可以用的意思。
Toast.makeText(context, "-----------------", 0).show();
//TODO : 判断是否被挂载
}
// 创建文件对象,获取到SD卡的路径
File file = new File(Environment.getExternalStorageDirectory(), "info.txt");
try {
// 文件输出流
FileOutputStream fos = new FileOutputStream(file);
// 写数据,zhangsan##123
fos.write((username + "##" + password).getBytes());
// 关闭输出流
fos.close();
return true;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
}