I've been making a program which reads several strings from a Notepad file which's location is set through user input. Then they enter a string which is in the file, a positive message is shown if it's not then a negative one is shown.
However I can only scan the first string of the file and return whether that's a yes or no. How do I change this code so it scans every string in the file and THEN tell us whether the word is in the file.
public static void main(String[] args)throws IOException {
// TODO code application logic here
String phrase, phrase2;
Scanner fileScan;
Scanner scan = new Scanner (System.in);
System.out.println ("Input file:");
phrase = scan.nextLine();
fileScan = new Scanner (new File(phrase));
System.out.println ("Enter string to search for: ");
phrase2 = scan.nextLine();
if (fileScan.hasNext(phrase2)) {
System.out.println("This file does contain the string \"" + phrase2 + "\"");
}
else if (phrase != phrase2) {
System.out.println("This file does not contain the string \"" + phrase2 + "\"");
}
}
}
And of course suggest any help/advice you are able to!!