我正在尝试在scala中读取csv文件的值。
val bufferedSource = io.Source.fromFile(destFile);
for (line <- bufferedSource.getLines) {
rows += line.split(",").map(_.trim)
}
但是当我在做io.Source.fromFile(destFile)时;我得到了一个例外
java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(CoderResult.java:281)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:161)
at java.io.BufferedReader.readLine(BufferedReader.java:324)
at java.io.BufferedReader.readLine(BufferedReader.java:389)
at scala.io.BufferedSource$BufferedLineIterator.hasNext(BufferedSource.scala:70)
at scala.collection.Iterator.foreach(Iterator.scala:929)
at scala.collection.Iterator.foreach$(Iterator.scala:929)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1417)
at TestFileProcessZip7z$.$anonfun$main$1(TestFileProcessZip7z.scala:79)
at TestFileProcessZip7z$.$anonfun$main$1$adapted(TestFileProcessZip7z.scala:34)
at scala.collection.immutable.List.foreach(List.scala:389)
at TestFileProcessZip7z$.main(TestFileProcessZip7z.scala:34)
at TestFileProcessZip7z.main(TestFileProcessZip7z.scala)
()
如何解决上述问题?提前致谢
答案 0 :(得分:0)
尝试将字符集赋予 ISO-8859-1 val bufferedSource = io.Source.fromFile(destFile,“ ISO-8859-1”);