Here you can find the source of formatSize(long size)
public static String formatSize(long size)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { public static String formatSize(long size) { if (size > 1000000000) return DecimalFormat.getNumberInstance().format(size / 1000000000) + " GB"; if (size > 1000000) return DecimalFormat.getNumberInstance().format(size / 1000000) + " MB"; if (size > 1000) return DecimalFormat.getNumberInstance().format(size / 1000) + " KB"; return DecimalFormat.getNumberInstance().format(size) + " B"; }/* w ww . j ava 2 s . c o m*/ }