您好,登錄后才能下訂單哦!
1,數據的保存
File file=new File(Environment.getExternalStorageDirectory(), name); try { FileOutputStream fos=new FileOutputStream(file); fos.write(content.getBytes()); fos.close(); Toast.makeText(getApplicationContext(),"保存成功", 200).show(); }catch (Exception e) { Toast.makeText(getApplicationContext(),"保存失敗", 200).show(); e.printStackTrace(); } |
2,數據的讀取
File file = new File(Environment.getExternalStorageDirectory(), name); try { FileInputStream fis= new FileInputStream(file); BufferedReader br =new BufferedReader(new InputStreamReader(fis)); //讀取文檔的數據 String content =br.readLine(); //拆分字符串 String [] str =content.split("="); //顯示數據 if(!content.isEmpty()){ et_name.setText(str[0]); et_password.setText(str[1]); } } catch (Exception e) { e.printStackTrace(); } } }); |
注意:保存數據記得注冊
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE”/> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> |
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。