Here you can find the source of humanReadableByteCount(long bytes)
public static String humanReadableByteCount(long bytes)
//package com.java2s; import java.util.Locale; public class Main { private static final int UNIT = 1024; public static String humanReadableByteCount(long bytes) { if (bytes < UNIT) { return bytes + "B"; }// www . ja v a 2s.c om int exp = (int) (Math.log(bytes) / Math.log(UNIT)); String pre = String.valueOf("KMGTPE".charAt(exp - 1)); return String.format(Locale.US, "%.1f%sB", bytes / Math.pow(UNIT, exp), pre); } }