Here you can find the source of bytesToHumanReadable(int bytes)
public static String bytesToHumanReadable(int bytes)
//package com.java2s; //License from project: Open Source License public class Main { public static String bytesToHumanReadable(int bytes) { float fbytes = (float) bytes; String[] mags = new String[] { "", "k", "m", "g", "t" }; int magIndex = 0; while (fbytes >= 1024) { fbytes /= 1024;//w w w. j a v a 2s .co m magIndex++; } return String.format("%.2f%sb", fbytes, mags[magIndex]); } }