Android Directory Size Get getDirLength(File dir)

Here you can find the source of getDirLength(File dir)

Description

get Dir Length

Declaration

public static long getDirLength(File dir) throws IOException 

Method Source Code

//package com.java2s;

import java.io.File;

import java.io.IOException;

public class Main {

    public static long getDirLength(File dir) throws IOException {
        if (dir.isFile())
            throw new IOException("BadInputException: not a directory.");
        long size = 0;
        File[] files = dir.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                File file = files[i];
                // file.getName(); 
                // System.out.println(file.getName()); 
                long length = 0;
                if (file.isFile()) {
                    length = file.length();
                } else {
                    length = getDirLength(file);
                }//from w  w w .  j  a  va  2 s . c om
                size += length;
            }// for 
        }// if 
        return size;
    }
}

Related

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