Java Long Number Readable Format getHumanReadableSize(long fileSize)

Here you can find the source of getHumanReadableSize(long fileSize)

Description

get Human Readable Size

License

Apache License

Declaration

public static String getHumanReadableSize(long fileSize) 

Method Source Code

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

import java.text.DecimalFormat;

public class Main {

    public static String getHumanReadableSize(long fileSize) {

        String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
        int unitIndex = (int) (Math.log10(fileSize) / 3);
        double unitValue = 1 << (unitIndex * 10);
        return new DecimalFormat("#,##0.#").format(fileSize / unitValue)
                + " " + units[unitIndex];

    }//w w  w  .  j  a va2  s  .co m
}

Related

  1. formatBytes(long size)
  2. getHumanReadable(long ts, boolean addUTC)
  3. getHumanReadableFileSize(Long fileSize)
  4. getHumanReadableIfSpeed(long ifSpeed)
  5. getHumanReadableSize(long bytes)
  6. getHumanReadableSize(long size, long unit, String unitName)
  7. getHumanSize(long size)
  8. getMaxHeap(String message)
  9. getTrafficString(long bytes)