Here you can find the source of formatBytes(long bytes)
public static String formatBytes(long bytes)
//package com.java2s; //License from project: Apache License public class Main { public static String formatBytes(long bytes) { String size = ""; if (bytes > 1024 * 1024) size += (bytes / 1024 / 1024) + " MB (" + bytes + " Bytes)"; else if (bytes > 1024) size += (bytes / 1024) + " KB (" + bytes + " Bytes)"; else if (bytes > 1) size += bytes + " Bytes"; else//from w w w .j a va 2 s. co m size += bytes + " Byte"; return size; } }