Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve java.nio.charset.UnmappableCharacterException in Scala 2.8.0?

I'm using Scala 2.8.0 and trying to read pipe delimited file like in code snipped below:

object Main {
  def main(args: Array[String]) :Unit = {
    if (args.length > 0) {
      val lines = scala.io.Source.fromPath("QUICK!LRU-2009-11-15.psv")
     for (line <-lines)
       print(line)
    }
  }
}

Here's the error:

Exception in thread "main" java.nio.charset.UnmappableCharacterException: Input length = 1 at java.nio.charset.CoderResult.throwException(CoderResult.java:261) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:319) at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158) at java.io.InputStreamReader.read(InputStreamReader.java:167) at java.io.BufferedReader.fill(BufferedReader.java:136) at java.io.BufferedReader.read(BufferedReader.java:157) at scala.io.BufferedSource$$anonfun$1$$anonfun$apply$1.apply(BufferedSource.scala:29) at scala.io.BufferedSource$$anonfun$1$$anonfun$apply$1.apply(BufferedSource.scala:29) at scala.io.Codec.wrap(Codec.scala:65) at scala.io.BufferedSource$$anonfun$1.apply(BufferedSource.scala:29) at scala.io.BufferedSource$$anonfun$1.apply(BufferedSource.scala:29) at scala.collection.Iterator$$anon$14.next(Iterator.scala:149) at scala.collection.Iterator$$anon$2.next(Iterator.scala:745) at scala.collection.Iterator$$anon$2.head(Iterator.scala:732) at scala.collection.Iterator$$anon$24.hasNext(Iterator.scala:405) at scala.collection.Iterator$$anon$20.hasNext(Iterator.scala:320) at scala.io.Source.hasNext(Source.scala:209) at scala.collection.Iterator$class.foreach(Iterator.scala:534) at scala.io.Source.foreach(Source.scala:143) ... at infillreports.Main$.main(Main.scala:8) at infillreports.Main.main(Main.scala) Java Result: 1

like image 572
Roman Kagan Avatar asked Nov 18 '09 16:11

Roman Kagan


1 Answers

object Main {
  def main(args: Array[String]) :Unit = {
    if (args.length > 0) {
      val lines = scala.io.Source.fromPath("QUICK!LRU-2009-11-15.psv")("UTF-8")
      for (line <-lines)
        print(line)
    }
  }
}
like image 119
Daniel C. Sobral Avatar answered Oct 22 '22 03:10

Daniel C. Sobral