数据存储之--内存卡的存储

发布时间:2020-07-09 15:20:23 作者:InProvence
来源:网络 阅读:262

1,数据的保存

File file=new File(Environment.getExternalStorageDirectory(), name);

                  try {

                     FileOutputStream  fos=new FileOutputStream(file);

                     fos.write(content.getBytes());

                     fos.close();

                       Toast.makeText(getApplicationContext(),"保存成功", 200).show();

                  }catch (Exception e) {

                       Toast.makeText(getApplicationContext(),"保存失败", 200).show();

                      e.printStackTrace();

                  }

2,数据的读取

File file = new File(Environment.getExternalStorageDirectory(), name);      

              try {

                  FileInputStream fis= new FileInputStream(file);

                  BufferedReader br =new BufferedReader(new InputStreamReader(fis));

                  //读取文档的数据

                  String content =br.readLine();

                  //拆分字符串

                  String [] str =content.split("=");

               //显示数据

                  if(!content.isEmpty()){

                     et_name.setText(str[0]);

                     et_password.setText(str[1]);

                  }

              } catch (Exception e) {               

                  e.printStackTrace();

              }            

           }

       });

注意:保存数据记得注册

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE”/>

<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>


推荐阅读:
  1. 大数据运营之数据存储
  2. 数据存储级别

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

存储 数据存储 内存卡

上一篇:解决mysql文字乱码的方法

下一篇:python为什么比较慢

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》