I want to compare the value of edit text with all the lines in a file.(the file is word list) .
i have done this ,
try{
final InputStream file = getAssets().open("words.txt");
reader = new BufferedReader(new InputStreamReader(file));
String line = reader.readLine();
while(line != null){
line = reader.readLine();
if(ss == line.toLowerCase()){
Toast.makeText(this, "Working!", Toast.LENGTH_SHORT)
.show();
}
else{
Toast.makeText(this, "Not found !", Toast.LENGTH_SHORT)
.show();
}
}
} catch(IOException ioe){
ioe.printStackTrace();
}
here ss is the value of textfield.
String ss = (res.getText()).toString();
this is the words.txt file https://raw.githubusercontent.com/eneko/data-repository/master/data/words.txt
But the above code is not working.
EDIT :
I have checked whether the file is opening or not, the problem is file is not opening.
try{
final InputStream file = getAssets().open("words.txt");
Toast.makeText(this, "File Opened", Toast.LENGTH_SHORT)
.show();
reader = new BufferedReader(new InputStreamReader(file));
String line ;
while((line = reader.readLine()) != null){
if(ss.equalsIgnoreCase(line)){
Toast.makeText(this, "Working!", Toast.LENGTH_SHORT)
.show();
TextView tv = myTextViewList.get(counter);
tv.setText(line);
}
else{
Toast.makeText(this, "Not found !", Toast.LENGTH_SHORT)
.show();
}
}
} catch(IOException ioe){
ioe.printStackTrace();
}
Try this
Replace "
==
" either with "equalsIgnoreCase
" or "equals
"