保存信息到手机里
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; }
相关文章推荐
- MiniTwitter记住密码等功能实现
- 大概简介
- 武当三丰太极拳28式 第一式 详解版
- sql 使用存储过程传递列名或表名作为参数
- Activity与Fragment数据传递之Fragment之间获取数据 分类: Android 2015-07-02 10:33 11人阅读 评论(0) 收藏
- 线程——委托InvokeRequired和Invoke
- ado.net 基础(一)
- GCD block(一)
- Leetcode|Surrounded Regions
- 深入探究Lua中的解析表达式
- Jquery简单整理
- 地球经纬 度与度分秒格式的转化
- 【LeetCode】211. Add and Search Word - Data structure design
- 织梦dede给文章列表加序号
- 欢迎使用CSDN-markdown编辑器
- 第一次写博客,以后旨在翻译或者转载一些国外的技术文档,加上自己的实验心得,谢谢支持
- ARP请求过程(可用于ip冲突检测)
- 安装两个jdk后eclipse启动不了的一个情况
- GPU:并行计算利器
- 二叉搜索树(BST)相关知识总结