Here you can find the source of readable(long bytes)
public static String readable(long bytes)
//package com.java2s; //License from project: Apache License import java.text.DecimalFormat; public class Main { private static final long KB = 1024; private static final long MB = 1024 * KB; private static final long GB = 1024 * MB; public static String readable(long bytes) { DecimalFormat df = new DecimalFormat("#.###"); if (bytes >= GB) { return df.format((double) bytes / GB) + "GB"; } else if (bytes >= MB) { return df.format((double) bytes / MB) + "MB"; } else if (bytes >= KB) { return df.format((double) bytes / KB) + "KB"; } else {/*from w w w . j a v a 2s . c o m*/ return bytes + ""; } } }