here is my program that can read through a txt file line by line to find one word named "friends". if any line contains of this word then get the line and check my precised friend's name is mentioned there or not ?

its working when my precised named only one, but what should i do if it will more than one ?

suppose, my txt file contains like this:

my childhood friends named Jassei and Kathy.
Abbey, Kathy and Borny were my school friends.
In college, Jami and Abbey were good friends.
Here in university, Jacky and Hatchi are my new friends.

and code:

String target="friends";
String reading=new String();
String findName="Kathy";

FileReader fr = new FileReader ("C:/Java/Test1.txt");   
BufferedReader reader = new BufferedReader (fr);

while (reader.ready()){ 
if (reading.indexOf(target)!= -1 ){ 
String line = result.substring(0, result.indexOf(target));
if (line.indexOf(findName) !=-1) {
System.out.println("Name found in:"+ indexOf(findName));
catch(IOException ioe){}

my question is, at a time i want to search more friend names not only "kathy"..

if i use like this,
String[] findNames={"kathy", "Borny", "Jakcy"}
then what to do ??
or any idea pls ??

Edited by doha786: n/a

8 Years
Discussion Span
Last Post by doha786

Ever heard of "for" loop?

for(int = 0; i < findNames.length; i++){
    if (line.indexOf(findName[i]) !=-1) {
        System.out.println("Name found in:"+ indexOf(findName));
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.