Here you can find the source of formatSize(long v)
public static String formatSize(long v)
//package com.java2s; //License from project: LGPL public class Main { public static String formatSize(long v) { if (v < 1024) return v + " B"; int z = (63 - Long.numberOfLeadingZeros(v)) / 10; return String.format("%.1f %sB", (double) v / (1L << (z * 10)), " KMGTPE".charAt(z)); }/* w w w .j a v a2s. c o m*/ }