android 短信 存储,Android-存储用户登录信息

这篇博客介绍了如何在Android应用中实现用户登录时EditText输入的用户名和密码的存储与回显。通过使用AndroidContext的openFileOutput方法将信息写入私人目录,然后使用FileInputStream和BufferedReader读取并解析存储的内容,最后将信息填充到EditText中。整个过程确保了数据的安全性和用户体验。
摘要由CSDN通过智能技术生成

用户登录

目的:

完成EditText中输入用户名和密码,并存储在私人目录中以备调用

1、 存储输入的内容:

利用Android Context类openFileOutput方法

FileOutputStream fileOutputStream = context.openFileOutput("userinfo", context.MODE_PRIVATE);

关于openFileOutput文档注释:

Open a private file associated with this Context's application package for writing. Creates the file if it doesn't already exist.

No permissions are required to invoke this method, since it uses internal storage.

Return:

The resulting FileOutputStream.

关于FileOutputStream    writes bytes to a file 所以

fileOutputStream.write(userinfo.getBytes());

An output stream that writes bytes to a file. If the output file exists, it can be replaced or appended to. If it does not exist, a new file will be created.

2、 回显存储的信息

FileInputStream fileInputStream = context.openFileInput("userinfo");

BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));

String readLine = bufferedReader.readLine();

String[] split = readLine.split("##");

HashMap hashMap = new HashMap();

hashMap.put("username", split[0]);

hashMap.put("password", split[1]);

bufferedReader.close();

fileInputStream.close();

return hashMap;

参看Java内容

Mainactivity部分

Mapmap=UserInfoUtil.getUserInfo(mContext);

if(map !=null){

String username = map.get("username");

String password = map.get("password");

et_username.setText(username);

et_password.setText(password);

cb_remPass.setChecked(true);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值