Reputation: 313
I am trying to read values of a csv file in scala.
val bufferedSource = io.Source.fromFile(destFile);
for (line <- bufferedSource.getLines) {
rows += line.split(",").map(_.trim)
}
However when I am doing io.Source.fromFile(destFile); I am getting an exception
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)
()
How do I resolve the above issue? Thanks in advance
Upvotes: 0
Views: 2272
Reputation: 11
Try giving charset to ISO-8859-1 val bufferedSource = io.Source.fromFile(destFile, "ISO-8859-1");
Upvotes: 1