Here you can find the source of folderSize(File directory)
public static long folderSize(File directory)
//package com.java2s; import java.io.File; public class Main { public static long folderSize(File directory) { long length = 0L; if (directory != null) { File[] files = directory.listFiles(); if (files == null) { return 0L; }//from w w w.j a v a 2 s . c om File[] arrayOfFile1; int j = (arrayOfFile1 = files).length; for (int i = 0; i < j;) { File file = arrayOfFile1[i]; try { if (file.isFile()) { length += file.length(); } else if (file.isDirectory()) { length += folderSize(file); } if (length < 0L) { break; } i++; } catch (Exception ioe) { ioe.printStackTrace(); } } } return length; } }