Use the sizeOfDirectory( )
method on FileUtils
. The following
example returns the size of the temp
directory:
File dir = new File( "temp" ); long dirSize = FileUtils.sizeOfDirectory( );
If temp
contains a number
files, FileUtils.sizeOfDirectory( )
will return the sum of the size of every file in temp
. If temp
contains subdirectories, this method
will recursively call sizeOfDirectory(
)
on each subdirectory to obtain the size of each
subdirectory, and it will return the sum of these sizes.