标签:系统数据的保存
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"; Stringcontent=user+"="+pwd; // StringBuffer sb = newStringBuffer(); String content =sb.append(userName).append("=").append(password).toString();
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(); } }
} }); |
1,2数据的读取
btn_show.setOnClickListener(new OnClickListener() {
@Override publicvoid onClick(View v) { String name="data.txt"; try { FileInputStream fis=openFileInput(name); BufferedReaderbr=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(); } } }); |
标签:系统数据的保存
原文地址:http://9882931.blog.51cto.com/9872931/1612544