Here you can find the source of toHumanSize(long bytes)
public static String toHumanSize(long bytes)
//package com.java2s; //License from project: Open Source License public class Main { private static String[] units = { "B", "KB", "MB", "GB", "TB", "PB" }; public static String toHumanSize(long bytes) { int unit = 0; double value = bytes; while (value > 4096) { value = value / 1024;/*from ww w. j a v a 2 s .co m*/ unit++; } if (unit == 0) { return String.valueOf(bytes) + units[unit]; } return String.format("%.1f%s", value, units[unit]); } }