scala – java.nio.charset.MalformedInputException读取流时
发布时间:2020-12-16 19:06:42 所属栏目:安全 来源:网络整理
导读:我使用以下代码来读取数据.它抛出 java.nio.charset.MalformedInputException. 该文件可以正常打开,但它包含非ASCII字符.反正我可以解决这个问题吗? Source.fromInputStream(stream).getLines foreach { line = // store items on the fly lineParser(line.
我使用以下代码来读取数据.它抛出
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()) } } 解决方法
尝试Source.fromInputStream(流)(io.Codec(“UTF-8”))或您需要的任何字符集.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |