Android阅读文件,错误

时间:2014-02-01 11:04:23

标签: java android

单独固定 有很多问题,我一步一步地注意到他们调试,谢谢(

我有一些奇怪的错误,应用程序崩溃了。 问题在于此代码:

File sdcard = Environment.getExternalStorageDirectory();
    File file = new File(sdcard,"Potato/Users.txt");

////////// ------ CHECK IF USER EXISTS BEFORE REGISTER -----------


    //Get the text file


    //Read text from file
    StringBuilder text = new StringBuilder();

    try {
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line;

        while ((line = br.readLine()) != null) 
        {
            text.append(line);
            text.append('\n');


            int start = text.indexOf("{");
            int end = text.indexOf("}");
            login50 = text.substring(start + 1, end - start - 1);

            int start2 = text.indexOf("[");
            int end2 = text.indexOf("]");
            password50 = text.substring(start + 1, end - start - 1);

            text=null;

            if(login50.equals(user))
            {
                annoying=false;
            }
        }
    }
    catch (IOException e) {
        //You'll need to add proper error handling here
    }
    /////////////////////////// ----- DONE --------------

我在我的应用程序中做了简单注册,2个字段:登录和密码。 txt文件看起来像这样:

登录{example};密码[示例]

代码在{}之间输入字符串作为登录名,并检查你在textfield上写的内容是否等于这个字符串。 如果是,请不要创建新帐户(恼人=假) 所有这些都在整个txt文件的循环中,检查你在textfield上写的是否是现有用户。

应用程序正在创建新用户,但如果您将名称写为现有用户,则应用程序崩溃。

是的,我拥有清单文件的所有权限(:

帮助? ):

1 个答案:

答案 0 :(得分:0)

尝试更改

String line;

String line="";