网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

数据的保存和读取

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://bjjierui.cn/article/pcioes.html

其他资讯