资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

数据的保存和读取

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();

                                        }          

                              }

                    });

 


分享文章:数据的保存和读取
文章URL:http://cdkjz.cn/article/pcioes.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220