I got an run time exception in my program while I am reading a file through a Scanner.
java.util.NoSuchElementException: No line found
at java.util
For whatever reason, the Scanner class also issues this same exception if it encounters special characters it cannot read. Beyond using the hasNextLine()
method before each call to nextLine()
, make sure the correct encoding is passed to the Scanner
constructor, e.g.:
Scanner scanner = new Scanner(new FileInputStream(filePath), "UTF-8");