您的位置:首页 > 其它

保存信息到手机里

2015-07-02 10:33 471 查看
/**
* 保存用户信息
*
* @param number
* @param pwd
* @return
*/
public static Boolean saveUserInfo(Context context, String number,
String pwd) {
try {
// String path = "data/data/com.example.qqlogin/123.txt";
File fsdir = context.getFilesDir();
File f = new File(fsdir, "123.txt");
FileOutputStream fs = new FileOutputStream(f);
String data = number + "##" + pwd;
fs.write(data.getBytes());
fs.flush();
fs.close();
return true;
} catch (Exception e) {

e.printStackTrace();
}
return false;
}

/**
* 返回用户信息
*
* @return
*/
public static Map<String, String> getUserInfo(Context context) {
try {
//String path = "data/data/com.example.qqlogin/123.txt";
File fsdir = context.getFilesDir();
File f = new File(fsdir, "123.txt");
FileInputStream fs = new FileInputStream(f);//获得一个文件输入流
BufferedReader buf = new BufferedReader(new InputStreamReader(fs)); //这里是吧一个文件流转化为输入流 在转化为字节流
String ss = buf.readLine();
String[] arr = ss.split("##");
Map<String, String> userinfo = new HashMap<String, String>();
userinfo.put("number", arr[0]);
userinfo.put("pwd", arr[1]);

return userinfo;
} catch (Exception e) {

e.printStackTrace();
}
return null;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: