How to skip invalid characters in stream in Java/Scala?
问题 For example I have following code Source.fromFile(new File( path), "UTF-8").getLines() and it throws exception Exception in thread "main" java.nio.charset.MalformedInputException: Input length = 1 at java.nio.charset.CoderResult.throwException(CoderResult.java:260) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:319) I don't care if some lines were not read, but how to skip invalid chars and continue reading lines? 回答1: You can influence the way that the charset decoding handles