Here you can find the source of getReadableSize(long size)
public static String getReadableSize(long size)
//package com.java2s; //License from project: Apache License import java.text.DecimalFormat; public class Main { public static String getReadableSize(long size) { final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" }; final int unitIndex = (int) (Math.log10(size) / 3); final double unitValue = 1 << (unitIndex * 10); final String readableSize = new DecimalFormat("#,##0.#").format(size / unitValue) + " " + units[unitIndex]; return readableSize; }//from w w w .ja v a 2s . c o m }