java - 使用资产文件夹中的文本文件匹配并重定向到下一个活动
问题描述
这是我使用的函数的代码:
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 和密码并重定向到家庭活动。
解决方案
您正在检查从文件“login.txt”中获取的字符串是否与输入到您的 editTexts 的用户 ID 和密码相等。例如,login.txt 有类似“user1,password”的内容,并且您在 edittext 中输入了“user1”作为 userId,在 edittext 中输入了“password”作为密码。检查文件中每个编辑文本和信息的内容是否相等将失败。“用户1,密码”!=“用户1”&&“用户1,密码”!=“密码”。您需要在“login.txt”文本的逗号符号之前仅检查 userId。与密码相同:检查密码(在逗号符号和空格之后)。
推荐阅读
- r - 在 R 中的几天内的特定时间平均数据
- python - 使用python从excel转置数据
- java - 如何在 Java Web 服务应用程序中保护 SQL Server 凭据
- c++ - C++20:强制使用指定的初始化器来模拟命名函数参数
- windows - 修剪 ArrayList 元素
- php - 用 preg_replace() 删除引号
- vuejs2 - 在侧边栏抽屉中显示项目 - 嵌套循环 Vue.js
- jquery - Vuejs中Preloader组件的问题
- javascript - 未捕获的类型错误:在输入单击时无法读取 null 的属性“样式”
- excel - 使用 VBA 将时间戳添加到 Excel