Java File Size Get getFileSize(String fileSize)

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

Description

get File Size

License

Apache License

Declaration

public static String getFileSize(String fileSize) 

Method Source Code

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

import java.text.DecimalFormat;

public class Main {

    public static String getFileSize(String fileSize) {
        String temp = "";
        DecimalFormat df = new DecimalFormat("0.00");
        double dbFileSize = Double.parseDouble(fileSize);
        if (dbFileSize >= 1024.0D) {
            if (dbFileSize >= 1048576.0D) {
                if (dbFileSize >= 1.073741824E9D) {
                    temp = df.format(dbFileSize / 1024.0D / 1024.0D / 1024.0D) + " GB";
                } else {
                    temp = df.format(dbFileSize / 1024.0D / 1024.0D) + " MB";
                }// w  w  w . j a  v a  2 s.  co m
            } else {
                temp = df.format(dbFileSize / 1024.0D) + " KB";
            }
        } else {
            temp = df.format(dbFileSize / 1024.0D) + " KB";
        }

        return temp;
    }
}

Related

  1. getFileSize(String filePath)
  2. getFileSize(String filepath)
  3. getFilesize(String filepath)
  4. getFileSize(String filePath)
  5. getFileSize(String filePath)
  6. getFileSize(String fn)
  7. getFileSize(String loc)
  8. getFileSize(String path)
  9. getFileSize(String path)