I'm needing to locate a string on a particular line in a text file that is composed of several lines of strings. However, my loop to find the text or the end of the file is eternally searching. I know the string is in the file. Here is the code I am using to locate the text - but be warned, if you try it on your system even with a simple text file it will go into an eternal loop.
I very much appreciate any tips or pointers to explain what I'm doing wrong here.
private static void locateText(String locateText, BufferedReader locateBffer) {
boolean unfound = true;
try
{
String line = locateBffer.readLine();
while (unfound)
{
line = locateBffer.readLine();
if ((line.equals(locateText)) || (line == null))
{
unfound = false;
}
}
}
catch(IOException e)
{
System.out.println("I/O error in locateText");
}
}
Update: Found the problem - it was not finding the match on the first line of the file.