Here you can find the source of getFileSize(long fileSize)
public static String getFileSize(long fileSize)
//package com.java2s; import java.text.DecimalFormat; public class Main { public static String getFileSize(long fileSize) { String fileSizeStr = ""; DecimalFormat df = new DecimalFormat("#.0"); if (fileSize < 1024) { fileSizeStr = df.format((double) fileSize) + "B"; } else if (fileSize < 1048576) { fileSizeStr = df.format((double) fileSize / 1024) + "K"; } else if (fileSize < 1073741824) { fileSizeStr = df.format((double) fileSize / 1048576) + "M"; } else {//from w ww .ja v a 2s . c o m fileSizeStr = df.format((double) fileSize / 1073741824) + "G"; } return fileSizeStr; } }