中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

數據的保存和讀取

發布時間:2020-07-14 13:58:41 來源:網絡 閱讀:566 作者:lang螞蟻 欄目:軟件技術

1數據的保存

btn_ok.setOnClickListener(new OnClickListener() {

                              @Override

                              public void 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

                              public void onClick(View v) {

                                        String name="data.txt";

                                        try {

                                                  FileInputStream fis=openFileInput(name);

                                                  BufferedReader br=new BufferedReader(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();

                                        }          

                              }

                    });

 

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

阿坝| 阿瓦提县| 蒙城县| 顺昌县| 咸丰县| 汕头市| 宝山区| 桐城市| 海门市| 威宁| 诸城市| 上犹县| 黄龙县| 绥宁县| 花垣县| 台中县| 囊谦县| 滁州市| 许昌县| 普兰县| 张掖市| 红河县| 永和县| 肇州县| 宿迁市| 寿宁县| 永清县| 舟曲县| 锦屏县| 焦作市| 金华市| 靖远县| 綦江县| 绥滨县| 建水县| 定安县| 津市市| 桓仁| 宣武区| 海阳市| 旬邑县|