Here you can find the source of getFileSize(File dir)
Parameter | Description |
---|---|
file | the file for which size to be found |
public static long getFileSize(File dir)
//package com.java2s; /******************************************************************************* * Copyright (c) 2000, 2011. 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 * //from w ww. j a v a 2 s. c o m * Contributors: * Fizer Khan, Yasmine - initial API and implementation *******************************************************************************/ import java.io.File; public class Main { /** * Get size of the file * * @param file * the file for which size to be found * @return size of the file */ public static long getFileSize(File dir) { long size = 0; if (dir.isFile()) { size = dir.length(); } else { File[] subFiles = dir.listFiles(); for (File file : subFiles) { if (file.isFile()) { size += file.length(); } else { size += getFileSize(file); } } } return size; } }