Java File Size Get getFileSize(String filePath)

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

Description

get File Size

License

Apache License

Declaration

public static long getFileSize(String filePath) 

Method Source Code

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

import java.io.File;

public class Main {

    public static long getFileSize(String filePath) {
        long size = 0;

        File file = new File(filePath);
        if (file != null && file.exists()) {
            size = file.length();//from www .  java 2s.  co m
        }
        return size;
    }

    public static String getFileSize(long size) {
        if (size <= 0)
            return "0";
        java.text.DecimalFormat df = new java.text.DecimalFormat("##.##");
        float temp = (float) size / 1024;
        if (temp >= 1024) {
            return df.format(temp / 1024) + "M";
        } else {
            return df.format(temp) + "K";
        }
    }
}

Related

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