Android Directory Size Get folderSize(File directory)

Here you can find the source of folderSize(File directory)

Description

folder Size

Declaration

public static long folderSize(File directory) 

Method Source Code

//package com.java2s;

import java.io.File;

public class Main {
    public static long folderSize(File directory) {
        long length = 0L;
        if (directory != null) {
            File[] files = directory.listFiles();
            if (files == null) {
                return 0L;
            }//from  w w w.j a  v a 2  s  .  c  om
            File[] arrayOfFile1;
            int j = (arrayOfFile1 = files).length;
            for (int i = 0; i < j;) {
                File file = arrayOfFile1[i];
                try {
                    if (file.isFile()) {
                        length += file.length();
                    } else if (file.isDirectory()) {
                        length += folderSize(file);
                    }
                    if (length < 0L) {
                        break;
                    }
                    i++;
                } catch (Exception ioe) {
                    ioe.printStackTrace();
                }
            }
        }
        return length;
    }
}

Related

  1. getDirLength(File dir)
  2. sizeOfDirectory(File directory)
  3. sizeOf(File spec)
  4. getDirectorySize(File f)