I have a file with the following contents
<div name="hello"></div>
and i need a java code that will read this file and print only the word *hello
This is what i have come up with
while (( line = bf.readLine()) != null)
{
linecount++;
int indexfound = line.indexOf("<div name");
if (indexfound > -1) {
Pattern p = Pattern.compile("\"([^\"]*)\"");
Matcher m = p.matcher(line);
while (m.find()) { System.out.println(m.group(1)); }
}
}
bf.close();
}} catch (IOException e) {
e.printStackTrace();
}}}
but the problem with this code is that if i make changes to the file such that it looks this way
<div name="hello" value="hi"></div>
then hi also gets printed but i want only hello to be printed