How to skip invalid characters in stream in Java/Scala?

前端 未结 4 1670
面向向阳花
面向向阳花 2021-02-02 12:53

For example I have following code

Source.fromFile(new File( path), \"UTF-8\").getLines()

and it throws exception

Exception in         


        
4条回答
  •  旧时难觅i
    2021-02-02 13:20

    Well, if it isn't UTF-8, it is something else. The trick is finding out what that something else is, but if all you want is avoid the errors, you can use an encoding that doesn't have invalid codes, such as latin1:

    Source.fromFile(new File( path), "latin1").getLines()
    

提交回复
热议问题