java.util.NoSuchElementException: No line found

前端 未结 6 739
失恋的感觉
失恋的感觉 2020-11-22 10:17

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         


        
6条回答
  •  粉色の甜心
    2020-11-22 10:31

    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");

提交回复
热议问题