Java tutorial
//package com.java2s; import java.io.File; public class Main { public static long getFolderSize(File file) throws Exception { long j = 0; File[] listFiles = file.listFiles(); for (int i = 0; i < listFiles.length; i++) { j = listFiles[i].isDirectory() ? j + getFolderSize(listFiles[i]) : j + listFiles[i].length(); } return j / 1048576; } }