您好,登录后才能下订单哦!
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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。