Here you can find the source of getFileSize(File file)
public static long getFileSize(File file)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.util.List; public class Main { public static long getFileSize(File file) { return getFileSize(file, null); }/* w w w. j a va 2 s . co m*/ public static long getFileSize(File file, List<String> excludeFileNamesList) { long size = 0; size += file.length(); File[] files = file.listFiles(); if (files != null) { for (File f : files) { if (excludeFileNamesList == null || !excludeFileNamesList.contains(f.getName())) { if (f.isDirectory()) { size += getFileSize(f, excludeFileNamesList); } else { size += f.length(); } } } } return size; } }