Here you can find the source of formatFileSize(long fileS)
public static String formatFileSize(long fileS)
//package com.java2s; //License from project: Apache License public class Main { public static String formatFileSize(long fileS) { java.text.DecimalFormat df = new java.text.DecimalFormat("#.00"); String fileSizeString = ""; if (fileS < 1024) { fileSizeString = df.format((double) fileS) + "B"; } else if (fileS < 1048576) { fileSizeString = df.format((double) fileS / 1024) + "KB"; } else if (fileS < 1073741824) { fileSizeString = df.format((double) fileS / 1048576) + "MB"; } else {/*www. j a va2 s .com*/ fileSizeString = df.format((double) fileS / 1073741824) + "G"; } return fileSizeString; } }