Reputation: 53
I know Java can use File.length(), FileChannel.size()
or RandomAccessFile.length()
to get a file's length, but this equals Linux's command "ls". However, when I create a file with a specific length as follows:
RandomAccessFile randomAccessFile = new RandomAccessFile(filePath,"rw");
randomAccessFile.setLength(10485760);
and use "ls -l filePath", I get the file's length is 10485760, but using "du filePath" only gets 0.
So, how to use Java to get the file's real used disk space?
Upvotes: 5
Views: 841
Reputation: 237
As per answer to question pertaining to Windows ,How do you get the file on disk, and not just the file size in Java?, there is no way to do it by one Java command, you can run Linux du
from Java, have a look here for technics How to run Linux commands in Java?.
Upvotes: 2