Here you can find the source of getFileSize(int fileSize)
public static final String getFileSize(int fileSize)
//package com.java2s; import java.text.DecimalFormat; public class Main { public static final String getFileSize(int fileSize) { double result = fileSize; if (result < 1024) { return result + "B"; }//from ww w. j a v a 2 s .c o m DecimalFormat df = new DecimalFormat("#0.00"); result = result / 1024; if (result < 1024) { return df.format(result) + "KB"; } result = result / 1024; if (result < 1024) { return df.format(result) + "MB"; } result = result / 1024; if (result < 1024) { return df.format(result) + "GB"; } result = result / 1024; return df.format(result) + "TB"; } }