Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 Pursuer (http://pursuer.me). * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html * * Contributors: * Pursuer - initial API and implementation ******************************************************************************/ import java.io.File; public class Main { public static long calcFileSpace(final File dir) { if (!dir.exists()) { return 0; } long ret = 0; if (dir.isDirectory()) { final File[] filies = dir.listFiles(); for (int i = 0; i < filies.length; i++) { final File curFile = filies[i]; if (curFile.isDirectory()) { ret += calcFileSpace(curFile); } else { ret += curFile.length(); } } } return ret; } }