Java File Size Readable Format formatSpaceUsage(long size)

Here you can find the source of formatSpaceUsage(long size)

Description

format Space Usage

License

Apache License

Declaration

static String formatSpaceUsage(long size) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    static String formatSpaceUsage(long size) {
        if (size < 1e4)
            return size + "B";
        else if (size < 1e7)
            return "" + Math.round(1D * size / 1024D) + "KB";
        else if (size < 1e10)
            return "" + Math.round(1D * size / 1e6) + "MB";
        else/*from w  w  w. jav a2s. c o  m*/
            return "" + Math.round(1D * size / 1e9) + "GB";
    }
}

Related

  1. formatSize(long size)
  2. formatSize(long v)
  3. formatSize(String strSize)
  4. formatSize(StringBuilder builder, Long size)
  5. formatSizeInBytes(int size)
  6. formatToolBarDisplay(String text, int size)
  7. getFileSizeInByte(File file)
  8. getFileSizeInBytes(File f)
  9. getFileSizeInMB(String fileName)