ekenne chilex ekenne chilex - 1 year ago 74
Android Question

Compare values between a .txt file and editText

I am trying to create a blacklist for my app, so any word that exists in the blacklist.txt file is inputted by user via editText will be flagged out. The code I have below is not doing anything and I don't know why.

private String comparevalue() {
BufferedReader buffered = null;

String val = editbox.getText().toString();
InputStream inputStream =getResources().openRawResource(R.raw.blacklist);
buffered = new BufferedReader(new InputStreamReader(inputStream));

try {
String line = buffered.readLine();
while (line != null) {

line = buffered.readLine();

}if (val.equalsIgnoreCase(line)) {
Toast.makeText(this, "Working", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(this,"Not found",Toast.LENGTH_LONG).show();
return buffered.toString();

Answer Source

change your code like this

while (line != null) {

        line = buffered.readLine();
        if (val.equalsIgnoreCase(line)) {
            Toast.makeText(this, "Working", Toast.LENGTH_LONG).show();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download