gpt4 book ai didi

scala - 为什么我在这个 Scala 中得到一个 java.nio.BufferUnderflowException

转载 作者:行者123 更新时间:2023-12-04 17:42:14 24 4
gpt4 key购买 nike

我正在尝试做一些 scripting in Scala , 处理一些日志文件:

scala> import io.Source
import io.Source

scala> import java.io.File
import java.io.File

scala> val f = new File(".")
f: java.io.File = .

scala> for (l <- f.listFiles) {
| val src = Source.fromFile(l).getLines
| println( (0 /: src) { (i, line) => i + 1 } )
| }
3658
java.nio.BufferUnderflowException
at java.nio.Buffer.nextGetIndex(Unknown Source)
at java.nio.HeapCharBuffer.get(Unknown Source)
at scala.io.BufferedSource$$anon$2.next(BufferedSource.scala:86)
at scala.io.BufferedSource$$anon$2.next(BufferedSource.scala:74)
at scala.io.Source$$anon$6.next(Source.scala:307)
at scala.io.Source$$anon$6.next(Source.scala:301)
at scala.Iterator$cla...

为什么我会得到这个 java.nio.BufferUnderflowException ?

注意 - 我正在处理 10 个日志文件,每个文件大小约为 1MB

最佳答案

我收到了 BufferUnderflowException当我打开一个带有错误编码的文件时出现异常。它包含非法字符(根据错误的编码),并抛出了这个误导性异常。

关于scala - 为什么我在这个 Scala 中得到一个 java.nio.BufferUnderflowException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1048618/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com