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?
Right-click the file and click Properties. The image below shows that you can determine the size of the file or files you have highlighted from in the file properties window. In this example, the chrome. jpg file is 18.5 KB (19,032 bytes), and that the size on disk is 20.0 KB (20,480 bytes).
Using the ls Command–l – displays a list of files and directories in long format and shows the sizes in bytes.
In Java, we can use Files. size(path) to get the size of a file in bytes.
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
java.nio.file.Files.size
from api:
public static long size(Path path) throws IOException
Returns the size of a file (in bytes)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With