为了账号安全,请及时绑定邮箱和手机立即绑定

使用资产文件夹中的文本文件来匹配并重定向到下一个活动

使用资产文件夹中的文本文件来匹配并重定向到下一个活动

森林海 2023-12-30 15:52:54
这是我使用的函数的代码: public void redirecttohome() {            //variable init            edtpass = (EditText) findViewById(R.id.edtpass);            edtuserid = (EditText) findViewById(R.id.edtuserid);            String text="";       try {       InputStream is = getAssets().open("login.txt");       int size = is.available();       byte [] buffer = new byte[size];       is.read(buffer);       text = new String (buffer);                 if (edtuserid.getText().toString().equals(text) && edtpass.getText().toString().equals(text)) {          startActivity(new Intent(getApplicationContext(), MainActivity.class));      }     else {Snackbar.make(parent_view, "Invalid UserID and Password", Snackbar.LENGTH_SHORT).show();}          is.close();    } catch (IOException e) {       Log.e("Error!", "Error occured while reading text file from Internal Storage!");    } }我想从保存在资产目录中的文本中检查用户 ID 和密码,并重定向到家庭活动。
查看完整描述

1 回答

?
慕仙森

TA贡献1827条经验 获得超7个赞

您正在检查从文件“login.txt”中抓取的字符串是否与输入到 editTexts 中的用户 ID 和密码相等。例如,login.txt 包含类似“user1,password”的内容,并且您已在 edittext 中输入“user1”作为 userId,并在 edittext 中输入“password”作为密码。检查文件中每个编辑文本和信息的内容是否相等将失败。“用户1,密码”!=“用户1”&&“用户1,密码”!=“密码”。您需要检查 userId 仅包含“login.txt”中文本的逗号符号之前的部分。与密码相同:检查密码(在逗号符号和空格之后)。



查看完整回答
反对 回复 2023-12-30
  • 1 回答
  • 0 关注
  • 52 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信