Java Android正在读取文件,错误
单独解决这个问题 有很多问题,我通过调试一步一步地注意到了,谢谢(: 我有一些奇怪的错误,应用程序崩溃了。 此代码中存在问题:Java Android正在读取文件,错误,java,android,Java,Android,单独解决这个问题 有很多问题,我通过调试一步一步地注意到了,谢谢(: 我有一些奇怪的错误,应用程序崩溃了。 此代码中存在问题: File sdcard = Environment.getExternalStorageDirectory(); File file = new File(sdcard,"Potato/Users.txt"); ////////// ------ CHECK IF USER EXISTS BEFORE REGISTER ----------- //
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 --------------
我在我的应用程序中做了简单的注册,两个字段:登录名和密码。
txt文件如下所示:
登录名{example};密码[示例]
代码将{}之间的字符串作为登录名,并检查您在textfield上写的内容是否等于此字符串。。
如果是,则不允许创建新帐户(恼人=错误)
所有这些都在整个txt文件的循环中进行,以检查您在textfield上写的内容是否是现有用户
应用程序正在创建新用户,但如果您将名称作为现有用户写入,应用程序将崩溃
是的,我拥有清单文件的所有权限(:
帮助?:尝试更改
String line;
到
logcat中有错误吗?有stacktrace吗?我们需要你的logcat!来吧,这怎么能改变任何事情?@FD_,我不确定,如果字符串行;为行分配内存。是吗?请让我知道。谢谢
String line="";