Here you can find the source of formatFileSize(long bytes)
public static String formatFileSize(long bytes)
//package com.java2s; //License from project: Apache License public class Main { public static String formatFileSize(long bytes) { if (bytes < 4096) { return bytes + " bytes"; } else if (bytes < 1024 * 1024) { return (Math.round(10 * bytes / 1024) / 10) + " kb"; } else {/* w w w. j ava2 s . co m*/ return (Math.round(10 * bytes / (1024 * 1024)) / 10) + " mb"; } } }