Here you can find the source of printByteSize(long bytes)
public static String printByteSize(long bytes)
//package com.java2s; public class Main { public static String printByteSize(long bytes) { if (bytes >= 1073741824) { return "" + (Math.round(bytes / 1073741824 * 100) / 100) + "G"; } else if (bytes >= 1048576) { return "" + (Math.round(bytes / 1048576 * 100) / 100) + "M"; } else if (bytes >= 1024) { return "" + (Math.round(bytes / 1024 * 100) / 100) + "K"; } else {/*from ww w .j a v a2 s. co m*/ return "" + bytes + "B"; } } }