数据的保存和读取

1数据的保存

公司专注于为企业提供网站设计制作、网站设计、微信公众号开发、商城网站建设微信小程序开发,软件按需定制制作等一站式互联网企业服务。凭借多年丰富的经验,我们会仔细了解各客户的需求而做出多方面的分析、设计、整合,为客户设计出具风格及创意性的商业解决方案,成都创新互联更提供一系列网站制作和网站推广的服务。

btn_ok.setOnClickListener(new OnClickListener() {

                              @Override

                              publicvoid onClick(View v) {

                                        String user =et_user.getText().toString().trim();

                                        String pwd =et_pwd.getText().toString().trim();

                                        if(user.isEmpty()||pwd.isEmpty()){

                                                  Toast.makeText(getApplicationContext(),"不能为空", 200).show();

                                        }else{

                                                   

                                                  String name="data.txt";

                                                  String content=user+"="+pwd;

                                                  try {

                                                   FileOutputStream fos=openFileOutput(name,MODE_PRIVATE);

                                                  

                                                   fos.write(content.getBytes());

                                                  

                                                   fos.close();

                                                             

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

                                                   

                                                  }catch (Exception e) {

                                                            //TODO Auto-generated catch block

                                                            e.printStackTrace();

                                                  }

                                        }

                               

                              }

                    });

 

 

 

 

2,数据的读取

 

 

btn_show.setOnClickListener(new OnClickListener() {

                               

                              @Override

                              publicvoid onClick(View v) {

                                        String name="data.txt";

                                        try {

                                                  FileInputStream fis=openFileInput(name);

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

                                                  //读取文档的数据

                                                  String content = br.readLine();

                                                  //拆分字符串

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

                                                  //显示的数据

                                                  if(!content.isEmpty()){

                                                            et_user.setText(strs[0]);

                                                            et_pwd.setText(strs[1]);

                                                  }

                                        }catch (Exception e) {

                                                  //TODO Auto-generated catch block

                                                  e.printStackTrace();

                                        }          

                              }

                    });

 


网站名称:数据的保存和读取
本文来源:http://bzwzjz.com/article/pcioes.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 网站制作公司 重庆网站设计 成都网站制作 网站建设公司 网站设计 泸州网站建设 营销网站建设 成都企业网站建设公司 重庆网站建设 网站建设公司 手机网站制作 高端网站设计推广 营销型网站建设 成都网站制作 成都网站建设流程 四川成都网站设计 成都网站制作 外贸营销网站建设 成都网站设计 成都网站设计 成都商城网站建设 高端定制网站设计