
Guindy National Park is located in Chennai , South India , one of the last remnants of tropical dry evergreen forest of the Coromandel Coast , Guindy Park was originally a game reserve.
and 2.txt is located biosphere reserve
I am getting an output like this now. Number of times Tim is: located Number of times Tim is: serve
the expected output is Number of times Tim is: located
code is as follows**import java.io.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Classnew
{
public static String getnew()
{
String data2 = "";
try {
BufferedReader br = new BufferedReader(new FileReader("2.txt"));
String devstr;
while ((devstr = br.readLine()) != null) {
System.out.println(devstr);
data2+=devstr+"\n";
}
} catch (IOException e) {
}
return data2;
}
}
public class Findwordphrase {
public static void main(String[] args) {
Classnew classnew = new Classnew();
String data2 =classnew.getnew();
System.out.println("Data of Class2(keyWrd): " + data2);
try {
BufferedReader br = new BufferedReader(new FileReader("reader.txt"));
String devstr;
while ((devstr = br.readLine()) != null) {
String text = devstr;
String text1 = text.replaceAll(" ","").replaceAll(" "," ");
System.out.println(text1);
String[] words = text1.split(" ");
for (String word : words)
{
String regex1 = "\\b"+data2+"\\b";
Pattern pattern1 = Pattern.compile(regex1);
Matcher matcher1 = pattern1.matcher(word);
String val = null;
while (matcher1.find()) {
val = matcher1.group();
System.out.println("Number of times Tim is: " +val );
}
}
}
} catch (IOException e) {
}//try catch ends
}
}**
If i give the input like this String regex1 = "\blocated|reserve|biosphere\b";
instead of this i am getting the result. I don't want to hard code the string. instead i want to get the value from the called file and get the result. String regex1 = "\b"+data2+"\b";
i am missing some part to get the correct output and not able to find that. If any one could find my mistake help me. please...
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.