保存内部文件以进行登录

时间:2010-12-27 11:55:31

标签: android

HY !!

我的应用程序中有一个登录表单,但我想保存/恢复应用程序内部的文本文件而不是内部手机内存。

是否有一些代码段?

我制作了一个内部文件保存/恢复,但它不起作用。

if (cb.isChecked())
                {
                    File file = new File("/mmt/sdcard/login.skip");
                    Writer output = null;
                    try
                    {
                         output = new BufferedWriter(new FileWriter(file));
                            output.write(etuser.getText().toString()+ ";" + etpw.getText().toString());
                            output.close();
                    }
                    catch (Exception e) {
                        // TODO: handle exception
                    }

                }

File file = new File("/mmt/sdcard/login.skip");
    if(file.exists())
    {   try
        {
          BufferedReader input =  new BufferedReader(new FileReader(file));
          while (( line = input.readLine()) != null){
             line2 = line;
            }
          etuser.setText(line2.split(";")[0]);
          etpw.setText(line2.split(";")[1]);
          input.close();
        }
        catch (Exception e) {
            // TODO: handle exception
        }
    }

1 个答案:

答案 0 :(得分:1)

修改:请参阅Internal Storage

替代, 使用SharedPreference它对您来说是私有的。而且不能以其他方式访问。 (对于非根电话,至少)