我使用以下代码读取数据,但是它抛出了java.nio.charset.MalformedInputException异常。文件可以正常打开,但包含非ASCII字符。有什么方法可以解决这个问题吗?
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()
这里是流构造代码:
def getStream(path: String) = {
if (!fileExists(path)) {
None
} else {
val fileURL = new URL(path)
val urlConnection = fileURL.openConnection
Some(urlConnection.getInputStream())
}
}