Here you can find the source of formatFromSize(long size)
public static String formatFromSize(long size)
//package com.java2s; public class Main { public static String formatFromSize(long size) { if (size == -1) return ""; String suffix = " B"; if (size >= 1024) { suffix = " KB"; size /= 1024;// w w w. j a v a2s. c om if (size >= 1024) { suffix = " MB"; size /= 1024; } } StringBuilder resultBuffer = new StringBuilder(Long.toString(size)); int commaOffset = resultBuffer.length() - 3; while (commaOffset > 0) { resultBuffer.insert(commaOffset, ','); commaOffset -= 3; } if (suffix != null) resultBuffer.append(suffix); return resultBuffer.toString(); } }