Tag: streamreader

如何在Java / Scala中跳过流中的无效字符?

例如,我有以下代码 Source.fromFile(new File( path), “UTF-8”).getLines() 它抛出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) 我不在乎是否有些行没有被读取,但是如何跳过无效的字符并继续读取行?