現在、sd カードでファイル タイプ.csvおよび.txtを検索しています。これらのファイルの行をトーストとして表示しています。定義されたキーワードを含む行のみを表示したいと思います。RuleBasedCollatorを使用する必要があるように思えますが、実装方法がわかりません。
それは私がこれを行うべき正しい方法ですか、それとも別のより良い解決策がありますか?
ありがとう
if
コード(私の質問がある2番目にコメントしました):
private void conductScan() {
File[] file = Environment.getExternalStorageDirectory().listFiles();
for (File f : file)
{
if (f.isFile() && f.getPath().endsWith(".xml") || f.getPath().endsWith(".txt")) {
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(f));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
if (line ) { //here I want to define if line contains "test" then show the toast"
Toast.makeText(getApplicationContext(),line,Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),"No keyewords found",Toast.LENGTH_LONG).show();
}
}
}
catch (IOException e) {
Toast.makeText(getApplicationContext(),"Error reading file!",Toast.LENGTH_LONG).show();
}
String [] mStrings=text.toString().split("\n");
}
}
}