Web | This Site

Java Basics Examples
Java Tutorial
Java Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM

| Home |  | References |  | Discussion Forums |  | About TP

# Java Examples - Directory Size

## Problem Description:

How to get the size of a directory?

## Solution:

Following example shows how to get the size of a directory with the help of FileUtils.sizeofDirectory(File Name) method of FileUtils class.

    import java.io.File;
    import org.apache.commons.io.FileUtils;

    public class Main {
       public static void main(String[] args) {
          long size = FileUtils.sizeOfDirectory
          (new File("C:/Windows"));
          System.out.println("Size: " + size + " bytes");
       }
    }

## Result:

The above code sample will produce the following result.

    Size: 2048 bytes

Advertisement

Online Image Processing

Indian Baby Names