tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | 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  :  
com/bethecoder/tutorials/commons_io/tests/DirectorySize.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.commons_io.tests;

import java.io.File;

import org.apache.commons.io.FileUtils;

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



 
  


  
bl  br