加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Scala文件slurp

发布时间:2020-12-16 09:32:59 所属栏目:安全 来源:网络整理
导读:关于这个问题 Read entire file in Scala? 对第一个答案有一个评论 but I’d hate for people not to know they can do “io.File(“/etc/passwd”).slurp” in trunk. 当我尝试这样做时,scala告诉我 error: object File is not a member of package io 我
关于这个问题

Read entire file in Scala?

对第一个答案有一个评论

but I’d hate for people not to know they can do “io.File(“/etc/passwd”).slurp” in trunk.

当我尝试这样做时,scala告诉我

error: object File is not a member of package io

我有scala 2.9.1-1。我做错了吗?

解决方法

文件不再是stdlib的一部分。相反,您应该使用scala.io.Source。要阅读整个文件,您可以做

val fileContents = io.Source.fromFile("my_file.txt").mkString

这应该避免大型文件。如果大文件使用Source.getLines,并逐行处理文件。源也有很多其他方便的方法,所以在这里查看这里http://www.scala-lang.org/api/current/index.html#scala.io.Source

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读