public String size(int size){
String hrSize = \"\";
int k = size;
double m = size/1024;
double g = size/1048576;
double t = size/1073741824;
I love this:
public static String getDynamicSpace(long diskSpaceUsed)
{
if (diskSpaceUsed <= 0) {
return "0";
}
final String[] units = new String[] { "B", "KiB", "MiB", "GiB", "TiB" };
int digitGroups = (int) (Math.log10(diskSpaceUsed) / Math.log10(1024));
return new DecimalFormat("#,##0.#").format(diskSpaceUsed / Math.pow(1024, digitGroups))
+ " " + units[digitGroups];
}