How to find the size of directory using FileUtils

In this tutorial we are going to see about How to find the size of directory using Java FileUtils sizeOfDirectory(File directory) method

public static long sizeOfDirectory(File directory)

Counts the size of a directory recursively (sum of the length of all files). Note that overflow is not detected, and the return value may be negative if overflow occurs. See sizeOfDirectoryAsBigInteger(File) for an alternative method that does not overflow.


directory – directory to inspect, must not be null


size of directory in bytes, 0 if directory is security restricted, a negative number when the real total is greater than Long.MAX_VALUE.


NullPointerException – if the directory is null



public class DirectorySize {

 public static void main(String[] args) {
   long sizeInBytes = FileUtils.sizeOfDirectory(new File("C:/JTC"));
       System.out.println("Directory Size in Bytes: " + sizeInBytes + " bytes");


Directory Size in Bytes: 240 bytes

Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. காஞ்சிபுரம் நாடாளுமன்ற தொகுதி களநிலவரம்
  2. How to replace the element from List
  3. How to get the size of Collection
  4. How to apply New smart Ration Card online
  5. How to convert List into Array
  6. How to add value to all types of Collections
  7. How to know the ration shop stock availability from mobile
  8. How to rotate element of List
  9. How to find min and max value from Collection
  10. How to convert Array into List in Java
  11. How to shuffle the element of collection (List)
  12. How to reverse the Collection (List)
  13. How to find the size of directory using FileUtils
  14. How to make collection read-only

Be the first to comment

Leave a Reply