我试图获取Scala中HDFS目录中文件的大小。我可以在REPL中执行以下操作:
Seq("/usr/bin/hdfs", "dfs", "-du", "-s", "/tmp/test").!但我不能将结果存储到值中。如何获得Scala目录中文件的大小?
发布于 2017-01-10 15:19:12
您使用的!方法来自ProcessBuilder。
(Seq[String]被隐式转换为ProcessBuilder,从而允许您访问!)。
/** Starts the process represented by this builder,
* blocks until it exits, and returns the exit code.
*/
abstract def !: Int如果您想要输出,请使用不同的方法,如!!
/** Starts the process represented by this builder,
* blocks until it exits, and returns the output as a String.
*/
abstract def !!: String我建议查看在ProcessBuilder上定义的其他方法。我肯定其中至少有一个能满足你的需要。
发布于 2017-01-10 15:14:40
我建议使用https://github.com/pathikrit/better-files
import better.files._
import java.io.{File => JFile}
val size = File("/usr/bin/hdfs").size
println(size)https://stackoverflow.com/questions/41571786
复制相似问题