Here you can find the source of convertFileSize(long size)
public static String convertFileSize(long size)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { public static String convertFileSize(long size) { long kb = 1024; long mb = kb * 1024; long gb = mb * 1024; DecimalFormat df = new DecimalFormat("#.00"); if (size >= gb) { return df.format((double) size / gb) + "GB"; } else if (size >= mb) { return df.format((double) size / mb) + "MB"; } else if (size >= kb) { return df.format((double) size / kb) + "KB"; } else//from w ww .ja v a2 s . c om return df.format((double) size) + "B"; } }