大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

数据的保存和读取

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://dzwzjz.com/article/pcioes.html
在线咨询
服务热线
服务热线:028-86922220
TOP