Here you can find the source of getHumanReadableSize(long fileSize)
public static String getHumanReadableSize(long fileSize)
//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 }