Here you can find the source of formatBytes(long bytes)
public static String formatBytes(long bytes)
//package com.java2s; //License from project: Artistic License public class Main { public static String formatBytes(long bytes) { if (bytes < 1024) { return bytes + "b"; }/* ww w .j a va 2 s. c o m*/ bytes = bytes / 1024; if (bytes < 1024) { return bytes + "kb"; } bytes = bytes / 1024; if (bytes < 1024) { return bytes + "mb"; } bytes = bytes / 1024; return bytes + "GB"; } }