当输入文件在下一行有一个字符串时,我试图继续循环,但我得到一个错误。知道为什么吗?
while( !((input = in.nextLine()).equals(""))){
...
}
输出:
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)