Java Disk Free Space Get getTreeSize(File root)

Here you can find the source of getTreeSize(File root)

Description

get Tree Size

License

LGPL

Declaration

public static long getTreeSize(File root) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.io.File;

public class Main {
    public static long getTreeSize(File root) {
        long size = 0;
        File files[] = root.listFiles();

        if (files == null)
            return size;

        for (File file : files) {
            if (file.isDirectory())
                size += getTreeSize(file);
            else//from   www.jav  a  2s  .  c om
                size += file.length();
        }
        return size;
    }
}

Related

  1. getFreeSpace(File file)
  2. getFreeSpace(String dir)
  3. getFreeSpace(String pathname)
  4. getFreeSpaceOnPartition(File f)
  5. getTreeSize(File root)
  6. getUnixFreeSpace(String pathname)