内存卡的数据保存与读取-创新互联

,内存卡

成都创新互联公司网站建设公司,提供网站制作、成都做网站,网页设计,建网站,PHP网站建设等专业做网站服务;可快速的进行网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,是专业的做网站团队,希望更多企业前来合作!

   2.1数据保存

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

                                                 try{

                                                           FileOutputStream   fos=newFileOutputStream(file);

                                                           fos.write(content.getBytes());

                                                           fos.close();

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

                                                 }  catch(Exception e) {

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

                                                           e.printStackTrace();

                                                 }

            

2.2数据读取

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

                                                 try{

                                                           FileOutputStream   fos=newFileOutputStream(file);

                                                           fos.write(content.getBytes());

                                                           fos.close();

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

                                                 }  catch(Exception e) {

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

                                                           e.printStackTrace();

                                                 }

  3,sharedprefrence (****)

      btn_ok.setOnClickListener(newOnClickListener() {

                      

                             @Override

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

                                                           //获取编辑器

                                                    Editor edit = sp.edit();

                                                                //保存数据

                                                    edit.putString("name", user);

                                                    edit.putString("pwd", pwd);

                                                    //提交保存

                                                    edit.commit();  

                                                 }                                

                             }

                   });


网站名称:内存卡的数据保存与读取-创新互联
本文URL:http://pwwzsj.com/article/ioepe.html