How to find file size in scala?

▼魔方 西西 提交于 2019-12-03 11:12:55
lreeder

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

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

import java.io.File;
val file:File = new File("your file path");
file.length()

java.nio.file.Files.size

from api:

public static long size(Path path) throws IOException

Returns the size of a file (in bytes)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!