Here you can find the source of getFileSizeRecursive(File file, boolean subFolders)
Parameter | Description |
---|---|
file | a parameter |
subFolders | a parameter |
public static long getFileSizeRecursive(File file, boolean subFolders)
//package com.java2s; /*//from ww w.ja va 2 s. c o m * Copyright (c) 2012 Diamond Light Source Ltd. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ import java.io.File; public class Main { /** * @param file * @param subFolders * @return long */ public static long getFileSizeRecursive(File file, boolean subFolders) { long size = 0; if (file.isDirectory()) { File[] files = file.listFiles(); if (files != null) { for (File element : files) { if (!subFolders && element.isDirectory()) { continue; } long tmpSize = getFileSizeRecursive(element, subFolders); if (tmpSize != -1) { size += tmpSize; } } return size; } return -1; } return file.length(); } }