Here you can find the source of getSize(final File path)
Parameter | Description |
---|---|
path | path |
public static long getSize(final File path)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { /**/*ww w . j av a 2 s . co m*/ * Gets the size of the path. * <p> * If the path is a directory the size is the sum of the size of all the files in the * directory and sub-directories. If the path is a file, the size is the size of the * file. * </p> * * @param path path * @return path size in bytes */ public static long getSize(final File path) { long size = 0; if (path.isFile()) { size = path.length(); } else { File[] subFiles = path.listFiles(); for (File file : subFiles) { if (file.isFile()) { size += file.length(); } else { size += getSize(file); } } } return size; } }