It seems my search method only searches the first line, nothing else. not sure why. It should read line by line for a match, and if not found there move onwards to the next line until all line are exhausted, but when I test it with a file that has more than one line and search for a string on say line 5 it returns: Search parameter NOT found in file.
String Search(String key) throws IOException {
int lines = 0;
String line = "";
String nextLine = "";
String foundAt = "";
BufferedReader BR = new BufferedReader(new FileReader(f));
try {
while ((nextLine = BR.readLine()) != null) {
line = nextLine.toLowerCase();
lines++;
StringTokenizer words = new StringTokenizer(line); //create tokenizer words with what is in line
while(words.hasMoreTokens()) { //while words has tokens left
if (words.nextToken().equals(key.toLowerCase())) //go to next token and compare to key
foundAt = foundAt + "\n" + lines + ": " + line;
//do nothing continue loop
}
}
BR.close();
} catch(FileNotFoundException e) {
}
if (foundAt == "")
foundAt = "Search parameter NOT found in file.";
return foundAt;
}