scala - 没有创建 Tmp 文件中的数据
问题描述
我有以下最大规模,我需要在其中创建一个临时文件并添加一些内容,调用 main 方法,然后查看是否产生了正确的输出。
我可以看到在“/tmp”中创建的文件,但它始终是空的。就像 BufferedWriter 没有写入它一样。我究竟做错了什么?
"provided with a non empty file" should {
import java.io.{BufferedWriter, File, FileWriter}
val log: File = File.createTempFile("data", ".log")
log.renameTo(new File(log.getAbsolutePath + "data.log"))
val bw = new BufferedWriter(new FileWriter(log))
bw.write("This is the temporary file content")
bw.close()
log.deleteOnExit()
"print info" in {
val stream = new java.io.ByteArrayOutputStream()
Console.withOut(stream) {
val args = Array(log.getAbsolutePath)
main(args)
}
assert(stream.toString.trim == "This is the temporary file content")
}
}
}
解决方案
推荐阅读
- java - 转向 jpql 查询
- sockets - 当客户端和服务器在不同的机器上时,getsockname() 不会返回正确的地址
- command - 我添加了一个东西,如果有人离开,我的机器人会 dm,但现在我只是不断收到错误消息
- html - href=“tel:” tel 中间有 +
- php - Laravel 抛出一个自定义的 ValidationException
- c++11 - c ++在模板函数的指针中约束模板参数
- ios - 如何将现有对象保存到 Core Data
- angular - ngStyle 与指令上调用函数之间的性能
- javascript - 将来自 rxjs 的多个 observable 组合到一个缓冲区中
- php - 如何发送多个 Laravel 邮件