Here you can find the source of formatSize(long bytes, String b, String kb, String mb, String gb)
public static String formatSize(long bytes, String b, String kb, String mb, String gb)
//package com.java2s; public class Main { private static final long K = 1024; private static final long M = 1024 * K; private static final long G = 1024 * M; public static String formatSize(long bytes, String b, String kb, String mb, String gb) { if (bytes > 16L * G) return (bytes / G) + gb; else if (bytes > 16L * M) return (bytes / M) + mb; else if (bytes > 16L * K) return (bytes / K) + kb; else/*from www . ja v a 2 s . com*/ return bytes + b; } }