Here you can find the source of formatSize(long bytes)
public static String formatSize(long bytes)
//package com.java2s; //License from project: Apache License import java.text.DecimalFormat; public class Main { public static long KB = 1024; public static long MB = 1024 * KB; public static long GB = 1024 * MB; public static long TB = 1024 * GB; public static String formatSize(long bytes) { DecimalFormat df = new DecimalFormat(".0"); if (bytes > TB) return df.format(bytes * 1.0d / TB) + "TB"; if (bytes > GB) return df.format(bytes * 1.0d / GB) + "GB"; if (bytes > MB) return df.format(bytes * 1.0d / MB) + "MB"; if (bytes > KB) return df.format(bytes * 1.0d / KB) + "KB"; return bytes + "B"; }//from www.ja v a2 s . com }