Java File Size Get getFileSizeFormat(double inputvalue)

Here you can find the source of getFileSizeFormat(double inputvalue)

Description

get File Size Format

License

Apache License

Declaration

public static String getFileSizeFormat(double inputvalue) 

Method Source Code

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

public class Main {

    public static String getFileSizeFormat(double inputvalue) {
        String outputvalue = "0";
        if (inputvalue >= 1024 * 1024) {
            outputvalue = formatFloat("###,##0.0", inputvalue / (1024 * 1024)) + "M";
        } else if (inputvalue >= 1024) {
            outputvalue = formatFloat("###,##0.0", inputvalue / 1024) + "K";
        } else {/*from   w w w. j  ava  2  s . c o m*/
            outputvalue = formatFloat("###,##0", inputvalue) + "Bytes";
        }
        return outputvalue;
    }

    public static String formatFloat(String format, double f) {
        StringBuffer formatString = new StringBuffer(format);
        java.text.DecimalFormat df = new java.text.DecimalFormat(formatString.toString());
        return df.format(f);
    }
}

Related

  1. getFileSize(String path)
  2. getFileSize(String path)
  3. getFilesize(String path)
  4. getFileSize2(String filename)
  5. getFileSizeAggregate(String[] files)
  6. getFileSizeFormat(String total_size)
  7. getFileSizeLabel(long sizeInBytes)
  8. getFileSizeRecursive(File file, boolean subFolders)
  9. getFileSizes(File f)