Here you can find the source of getFileSize(File file)
Parameter | Description |
---|---|
file | a parameter |
public static long getFileSize(File file)
//package com.java2s; //License from project: GNU General Public License import java.io.File; public class Main { /**//from w ww . j a v a 2 s. c om * Method for computing the size of a file or folder * * @param file * @return OL if it is not possible to compute, in other case size in bytes */ public static long getFileSize(File file) { if (file == null) return 0L; if (file.isFile()) return file.length(); if (!file.isDirectory()) return 0L; File[] subFiles = file.listFiles(); if (subFiles == null) return 0L; long size = 0L; for (File subFile : subFiles) { if (subFile == null) continue; if (subFile.isFile()) size += subFile.length(); else size += getFileSize(subFile); } return size; } }