tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Commons IO > Basic > Directory Size

Directory Size 

Apache Commons IO is a java library with simple IO utilities and filters. This requires the library commons-io-2.1.jar to be in classpath. The following example shows using FileUtils.sizeOfDirectory() API. It returns the size of directory in bytes by considering all files and directories with in it recursively.

File Name  :  
Author  :  Sudhakar KV
Email  :  [email protected]m
package com.bethecoder.tutorials.commons_io.tests;



public class DirectorySize {

   @param args
  public static void main(String[] args) {
    File dir = new File("C:/Temp");
    //Get size in bytes
    long dirSize = FileUtils.sizeOfDirectory(dir);
    System.out.println(dir + " size : " + FileUtils.byteCountToDisplaySize(dirSize));

It gives the following output,
C:\Temp size : 10 MB



Books Recommendation

Your Ad Here
bl  br