For example I have following code
Source.fromFile(new File( path), \"UTF-8\").getLines()
and it throws exception
Exception in
If you want to avoid invalid characters using Scala, I found this worked for me.
import java.nio.charset.CodingErrorAction
import scala.io._
object HelloWorld {
def main(args: Array[String]) = {
implicit val codec = Codec("UTF-8")
codec.onMalformedInput(CodingErrorAction.REPLACE)
codec.onUnmappableCharacter(CodingErrorAction.REPLACE)
val dataSource = Source.fromURL("https://www.foo.com")
for (line <- dataSource.getLines) {
println(line)
}
}
}