Java tutorial
//package com.java2s; import java.io.File; public class Main { public static long getFolderSize(File folder) throws IllegalArgumentException { // Validate if (folder == null || !folder.isDirectory()) throw new IllegalArgumentException("Invalid folder "); String list[] = folder.list(); if (list == null || list.length < 1) return 0; // Get size File object = null; long folderSize = 0; for (int i = 0; i < list.length; i++) { object = new File(folder, list[i]); if (object.isDirectory()) folderSize += getFolderSize(object); else if (object.isFile()) folderSize += object.length(); } return folderSize; } public static boolean isDirectory(File file) { return file.exists() && file.isDirectory(); } public static boolean isFile(File file) { return file.exists() && file.isFile(); } }