Here you can find the source of getDirLength(File dir)
public static long getDirLength(File dir) throws IOException
//package com.java2s; import java.io.File; import java.io.IOException; public class Main { public static long getDirLength(File dir) throws IOException { if (dir.isFile()) throw new IOException("BadInputException: not a directory."); long size = 0; File[] files = dir.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { File file = files[i]; // file.getName(); // System.out.println(file.getName()); long length = 0; if (file.isFile()) { length = file.length(); } else { length = getDirLength(file); }//from w w w . j a va 2 s . c om size += length; }// for }// if return size; } }