,比如我有下面的代码如何在Java/Scala中忽略流中的无效字符?
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)
我不在乎,如果某些行不读,而是如何跳过无效字符,并继续念台词?
+1将我介绍给StandardCharset。我想这么久。没有更多的catch(UnsupportedEncodingException e){//永远不会发生}' – Thilo
@Thilo:如果你坚持使用Java 6,那么Guava提供[Charsets'类](http://guava-libraries.googlecode.com /svn/trunk/javadoc/com/google/common/base/Charsets.html)执行相同的操作。我实际上是 –
。谢谢;-) – Thilo