Java Size Format formatFileSize(Long sizeBytes)

Here you can find the source of formatFileSize(Long sizeBytes)

Description

format File Size

License

Open Source License

Parameter

Parameter Description
bytes a parameter

Declaration

public static String formatFileSize(Long sizeBytes) 

Method Source Code

//package com.java2s;

import java.text.DecimalFormat;

public class Main {
    /**/*w w w . ja  v  a  2s.  co m*/
     * 
     * @param bytes
     * @return
     */
    public static String formatFileSize(Long sizeBytes) {
        String size = "";
        try {
            double dSize = (double) sizeBytes;
            if (dSize >= 1024) {
                dSize /= 1024;
                size = "K";
                if (dSize >= 1024) {
                    dSize /= 1024;
                    size = "M";
                }
            }
            size = new DecimalFormat("0.00").format(dSize) + size;
        } catch (Exception e) {
            size = sizeBytes.toString();
        }

        return size;
    }
}

Related

  1. formatFileSize(long size)
  2. formatFileSize(long size)
  3. formatFileSize(long size)
  4. formatFileSize(long size)
  5. formatFileSize(long size)
  6. formatFilesizeGB(long filesize, int fractionDigits)
  7. formatGameSize(int size)
  8. formatMemorySize(long size)
  9. formatPartSize(int size, NumberFormat format)