Java File Size Get getFileSize(String filePath)

Here you can find the source of getFileSize(String filePath)

Description

java get the file size

License

Open Source License

Parameter

Parameter Description
file a parameter

Exception

Parameter Description
Exception an exception

Declaration

public static double getFileSize(String filePath) 

Method Source Code

//package com.java2s;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;

public class Main {
    /**/* w  ww  .  j a v a  2s .  c o  m*/
     * java get the file size
     * 
     * @param file
     * @return
     * @throws Exception
     */
    public static double getFileSize(File file) {
        double size = 0;
        try {
            if (file.exists()) {
                FileInputStream fis = null;
                fis = new FileInputStream(file);
                size = fis.available();
                fis.close();
            } else {
                return 0;
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return size;
    }

    /**
     * java get the file size
     * 
     * @param file
     * @return
     * @throws Exception
     */
    public static double getFileSize(String filePath) {
        File file = new File(filePath);
        return getFileSize(file);
    }
}

Related

  1. getFileSize(String filename)
  2. getFileSize(String fileName, Logger log)
  3. getFileSize(String filename, String dir)
  4. getFileSize(String filePath)
  5. getFileSize(String filePath)
  6. getFileSize(String filepath)
  7. getFilesize(String filepath)
  8. getFileSize(String filePath)
  9. getFileSize(String filePath)