Java Size getReadableSize(long size)

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

Description

get Readable Size

License

Apache License

Declaration

public static String getReadableSize(long size) 

Method Source Code

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

import java.text.DecimalFormat;

public class Main {

    public static String getReadableSize(long size) {
        final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
        final int unitIndex = (int) (Math.log10(size) / 3);
        final double unitValue = 1 << (unitIndex * 10);
        final String readableSize = new DecimalFormat("#,##0.#").format(size / unitValue) + " " + units[unitIndex];
        return readableSize;
    }//from  w  w  w  .ja  v  a 2s . c o m
}

Related

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