如何在scala中查找文件大小? [英] How to find file size in scala?

查看:194
本文介绍了如何在scala中查找文件大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个scala脚本,需要知道文件的大小。我该怎么做呢?
在Python中我会做

I'm writing a scala script, that need to know a size of a file. How do I do this correctly? In Python I would do

os.stat('somefile.txt').st_size

和Scala?

推荐答案

使用Scala标准库无法实现此目的。不使用外部库,可以使用Java File.length()方法可以做到这一点。在Scala中,这看起来像:

There is no way to do this using the Scala standard libraries. Without resorting to external libraries, you can use the Java File.length() method do do this. In Scala, this would look like:

import java.io.File
val someFile = new File("somefile.txt")
val fileSize = someFile.length

如果你想要Scala特定的东西,您可以使用 scalax等外部框架。 io rapture.io

If you want something Scala-specific, you can use an external framework like scalax.io or rapture.io

这篇关于如何在scala中查找文件大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆