gpt4 book ai didi

java - 使用 Java printwriter 编写 Scala 文件 - 为什么文件编写器在此代码中停止?

转载 作者:行者123 更新时间:2023-11-30 11:35:55 25 4
gpt4 key购买 nike

<分区>

我正在处理 scala 测试用例并使用 printwriter 来填充一些数据。这对我来说没有任何意义 - 看起来 appender 只停止了 3/4。

您不需要字数统计代码,因为您可以看到文件中的最后一行不完整:

hello world duck duck sauce sauce mazing ninjakeyboard skills ninja
hello world duck duck sauce

日志:

[info] Give a file with 10 words repeated on 1000 lines and file handler 
[info] - should give us an array of 10000 words *** FAILED ***
[info] 8434 did not equal 10000 (WordCountFileHandler.scala:20)

代码:

import java.io.PrintWriter
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
import WordCountFileHandler.WordCountFileHandler

class WordCountFileHandler extends FlatSpec with ShouldMatchers {

"Give a file with 10 words repeated on 1000 lines and file handler" should "give us an array of 10000 words" in {
val filename = java.util.UUID.randomUUID().toString
val testFile = new PrintWriter( filename , "UTF-8")
for (x <- 1 to 1000) yield {testFile.println("hello world duck duck sauce sauce mazing ninjakeyboard skills ninja")}
testFile.close()


val testOutput = WordCountFileHandler (filename)
testOutput.size should equal(1)
//testOutput.head.foreach(println(_))
testOutput.head.size should equal (10000)
}
}

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