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; import java.text.NumberFormat; public class Main { private static final NumberFormat numberFormat = new DecimalFormat( "#,###.##"); public static String convertFileSize(long size) { String unit = "B"; if (size >= 1024) { size = size / 1024;//from w w w . j a v a2s. c o m unit = "KB"; } if (size >= 1024) { size = size / 1024; unit = "MB"; } if (size >= 1024) { size = size / 1024; unit = "GB"; } if (size >= 1024) { size = size / 1024; unit = "TB"; } return numberFormat.format(size) + unit; } }