例如我有以下代码
Source.fromFile(new File( path), "UTF-8").getLines()
并且它会抛出异常
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)
我不在意一些行未被读取,但如何跳过无效字符并继续读取行?
catch (UnsupportedEncodingException e) { // never happens }
了。+1。 - ThiloCharsets
类(http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/base/Charsets.html),它可以完成同样的功能。 - Joachim Sauer