Java Size getReadableByteSize(long size)

Here you can find the source of getReadableByteSize(long size)

Description

get Readable Byte Size

License

Open Source License

Declaration

public static String getReadableByteSize(long size) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.DecimalFormat;

public class Main {
    public static String getReadableByteSize(long size) {
        if (size <= 0) {
            return "0";
        }/* w w  w  .jav  a 2s. co  m*/
        final String[] units = new String[] { "B", "KB", "MB", "GB", "TB", "PB", "EB" };
        int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
        return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
    }
}

Related

  1. getDataSize(long size)
  2. getFontSizeInPoints(String fontSizeWithUnit)
  3. getFormatSize(double size)
  4. getFormatSize(long size)
  5. getFormattedSize(long size)
  6. getReadableSize(long size)
  7. getSize(long octets)
  8. getSizeAll(final long bytes)
  9. getSizeFormat()