Here you can find the source of sizeOf(File file)
public static long sizeOf(File file)
//package com.java2s; //License from project: Apache License import java.io.File; public class Main { public static long sizeOf(File file) { if (!file.exists()) { throw new IllegalArgumentException(file + " does not exist"); }//from w w w . ja v a 2 s .co m if (file.isDirectory()) { return sizeOfDirectory(file); } else { return file.length(); } } public static long sizeOfDirectory(File directory) { if (!directory.exists()) { String message = directory + " does not exist"; throw new IllegalArgumentException(message); } if (!directory.isDirectory()) { String message = directory + " is not a directory"; throw new IllegalArgumentException(message); } long size = 0; File[] files = directory.listFiles(); if (files == null) { // null if security restricted return 0L; } for (File file : files) { size += sizeOf(file); } return size; } }