友人 私は、テキスト ファイルを読み取って一致する単語を検索するコードを持っていますが、テキスト ファイルの検索中に不確実性があります。テキスト ファイルに単語が存在するにもかかわらず、一致する場合と一致しない場合があります。
コードは次のとおりです。
EditText et = (EditText) findViewById(R.id.editText1);
String display = null;
String search = "dadas";
//String current = "woot";
try {
InputStream is = getAssets().open("file.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(is));
while(br.readLine() != null){
if(search.equalsIgnoreCase(br.readLine())){
display = "found";
break;
}
}
br.close();
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
et.setText(display);
これが私のテキストファイルの内容です:
dadaist
dadaists
dadas
daddies
daddle
daddled
daddles
daddling
なぜこれが起こっているのか誰にもわかりますか?テキストファイルに「finish」という単語を追加して検索すると、常にそれが見つかります。しかし、私の検索語が「dadas」または「dadist」の場合、et で null が返されます。