Java File Size Get getFileSize(File file)

Here you can find the source of getFileSize(File file)

Description

get File Size

License

Open Source License

Declaration

public static long getFileSize(File file) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.util.List;

public class Main {
    public static long getFileSize(File file) {
        return getFileSize(file, null);
    }/*  w w w. j a  va  2  s .  co m*/

    public static long getFileSize(File file, List<String> excludeFileNamesList) {
        long size = 0;
        size += file.length();
        File[] files = file.listFiles();
        if (files != null) {
            for (File f : files) {
                if (excludeFileNamesList == null || !excludeFileNamesList.contains(f.getName())) {
                    if (f.isDirectory()) {
                        size += getFileSize(f, excludeFileNamesList);
                    } else {
                        size += f.length();
                    }
                }
            }
        }
        return size;
    }
}

Related

  1. getFileSize(File file)
  2. getFileSize(File file)
  3. getFileSize(File file)
  4. getFileSize(File file)
  5. getFileSize(File file)
  6. getFileSize(File file)
  7. getFileSize(File file)
  8. getFileSize(File file)
  9. getFileSize(File file)