這是我使用的函數(shù)的代碼: 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!"); } }我想從保存在資產(chǎn)目錄中的文本中檢查用戶 ID 和密碼,并重定向到家庭活動(dòng)。
1 回答

慕仙森
TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊
您正在檢查從文件“l(fā)ogin.txt”中抓取的字符串是否與輸入到 editTexts 中的用戶 ID 和密碼相等。例如,login.txt 包含類似“user1,password”的內(nèi)容,并且您已在 edittext 中輸入“user1”作為 userId,并在 edittext 中輸入“password”作為密碼。檢查文件中每個(gè)編輯文本和信息的內(nèi)容是否相等將失敗?!坝脩?,密碼”!=“用戶1”&&“用戶1,密碼”!=“密碼”。您需要檢查 userId 僅包含“l(fā)ogin.txt”中文本的逗號(hào)符號(hào)之前的部分。與密碼相同:檢查密碼(在逗號(hào)符號(hào)和空格之后)。
添加回答
舉報(bào)
0/150
提交
取消