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