Here you can find the source of toHumanReadableSize(long bytes)
public static String toHumanReadableSize(long bytes)
//package com.java2s; //License from project: Open Source License public class Main { public static String toHumanReadableSize(long bytes) { boolean si = false; int unit = si ? 1000 : 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + ""; // + (si ? "" : "i"); return String.format("%.2f %sB", bytes / Math.pow(unit, exp), pre); }/*from w w w. j ava 2s .c o m*/ }