Here you can find the source of formatFileSize(long size, String format)
Parameter | Description |
---|---|
size | a parameter |
format | K,M,G,T |
public static String formatFileSize(long size, String format)
//package com.java2s; //License from project: Apache License public class Main { public static String formatFileSize(long size, String format) { if (format.equals("K")) { return size / 1024.0 + "K"; }//from w ww. ja v a 2s . c om if (format.equals("M")) { return size / 1024.0 / 1024.0 + "M"; } if (format.equals("G")) { return size / 1024.0 / 1024.0 / 1024.0 + "G"; } if (format.equals("T")) { return size / 1024.0 / 1024.0 / 1024.0 / 1024.0 + "T"; } return size + "B"; } }