我目前正在 sd 卡中搜索任何文件类型.csv和.txt。我将这些文件的行显示为敬酒。我现在只想显示包含已定义关键字的行。在我看来,我应该使用RuleBasedCollator,但我不确定如何实现它。
这是我应该这样做的正确方法还是有另一种更好的解决方案?
谢谢
代码(我已经评论了if
我的问题所在的第二个):
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");
}
}
}