Here you can find the source of FormatSize(long size)
public static String FormatSize(long size)
//package com.java2s; /**//ww w . j a v a 2s .c o m * KTH Developed by Java * * @Copyright 2011 by Service Platform Development Team, KTH, Inc. All rights reserved. * * This software is the confidential and proprietary information of KTH, Inc. * You shall not disclose such Confidential Information and shall use it only * in accordance with the terms of the license agreement you entered into with KTH. */ public class Main { public static String FormatSize(long size) { String suffix = null; if (size >= 1024) { suffix = "KB"; size /= 1024; 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(); } }