Curly quotes causing Java Scanner hasNextLine() to be false — why?

前端 未结 3 1841
遥遥无期
遥遥无期 2021-01-17 12:22

I\'ve been having an issue getting the java.util.Scanner to read a text file I saved in Notepad, even though it works fine with others. Basically, when it tries to read the

3条回答
  •  醉酒成梦
    2021-01-17 12:47

    Some time ago I had similar problem with configuration file which was edited by the user. Because I never know what type of editor user will use I try this:

    org.mozilla.universalchardet.UniversalDetector
    

    available from here:

    https://code.google.com/p/juniversalchardet/
    

    The detecting char encoding is not simple thing so I can't be sure if this library works at any condition, but for me was sufficient. Have a look, maybe will help somehow to detect your encoding and later set it to Scanner.

提交回复
热议问题