I use the following code to read data. It throws java.nio.charset.MalformedInputException. The file I can open normally, but it does include non-ascii chars. Anyway I can fix this problem?
Source.fromInputStream(stream).getLines foreach { line =>
// store items on the fly
lineParser(line.trim) match {
case None => // no-op
case Some(pair) => // some-op
}
}
stream.close()
The stream construction code is here:
def getStream(path: String) = {
if (!fileExists(path)) {
None
} else {
val fileURL = new URL(path)
val urlConnection = fileURL.openConnection
Some(urlConnection.getInputStream())
}
}