Here you can find the source of humanReadableFileSize(long size)
public static String humanReadableFileSize(long size)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { public static String humanReadableFileSize(long size) { if (size <= 0) { return "0"; }/* ww w. j ava 2 s. c o m*/ final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" }; int magnitude = (int) (Math.log10(size) / Math.log10(1024)); return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, magnitude)) + " " + units[magnitude]; } }