ファイルの行を取得し、その行で特定のテキストを検索してから、その行と、同じ特定のテキストを含むファイル内の他のすべての行を返します。
私はこれまでのところこれを持っています:
public String searchText(String text, String file)
{
StringBuffer sb = new StringBuffer();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line = null;
while((line = br.readLine()) != null)
{
while(line.indexOf(text) > 0)
{
sb.append(line);
}
}
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
必要なときに使える機能でなければなりません。私のやりたいことを理解していただければ幸いです。よろしくお願いします。