我有一个132 kb的文件(你真的不能说它很大)我试图从Scala REPL中读取它,但是我无法读取过去的2048个char,因为它给了我一个java.nio.charset.MalformedInputException例外
这些是我采取的步骤:
val it = scala.io.Source.fromFile("docs/categorizer/usig_calles.json") // this is ok
it.take(2048).mkString // this is ok too
it.take(1).mkString // BANG!
java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(CoderResult.java:277)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:338)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
Run Code Online (Sandbox Code Playgroud)
知道什么可能是错的吗?
-
显然问题是该文件不是UTF编码的
我把它保存为UTF,一切正常,我只是在迭代器上发出mkString,它检索文件的全部内容
奇怪的是,这个错误只会引起前2048个字符的传递......