10.7. Obtaining the Size of a Directory

Problem

You need to know the size of everything contained within a directory.

Solution

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.83.176