How to find file size in scala?

Viewed 10222

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

and in Scala?

3 Answers

java.nio.file.Files.size

from api:

public static long size(Path path) throws IOException

Returns the size of a file (in bytes)

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

Related