Im trying to go on a loop while the input file has a string on the following line but im getting an error. Any idea why?
while( !((input = in.nextLine()).equals(""))){
...
}
Output:
Enter file name: input1.txt
evil live
Exception in thread "main" This is a palindrome
level
This is a palindrome
dog
Not a palindrome
java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1516)
at Palindrome.main(Palindrome.java:41)
Your code is not correct, because it is possible that the input would end without providing an empty line. You should check if a line is available before checking it for being empty: