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.*;

public class Main {

    public static long getFileSize(File file) {
        long fileSize = 0;

        if (file.exists()) {
            if (file.isDirectory()) {
                File[] files = file.listFiles();

                for (int i = 0; i < files.length; i++) {
                    fileSize += getFileSize(files[i]);
                }/* w  ww  . j  a  v a  2s  . co m*/
            } else {
                fileSize = file.length();
            }
        }
        return fileSize;
    }

    public static boolean exists(String filePath) {
        return new File(filePath).exists();
    }
}

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)