Java File Size Readable Format formatSize(long size)

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

Description

format Size

License

Apache License

Declaration

public static String formatSize(long size) 

Method Source Code

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

public class Main {

    public static String formatSize(long size) {
        if (size < 1024)
            return String.format("%d B", size);
        else if (size < 1024 * 1024)
            return String.format("%.2f KB", (double) size / 1024);
        else if (size < 1024 * 1024 * 1024)
            return String.format("%.2f MB", (double) size / (1024 * 1024));
        else if (size < 1024L * 1024 * 1024 * 1024)
            return String.format("%.2f GB", (double) size / (1024 * 1024 * 1024));
        else//from   w  w  w .ja v  a2  s  . co m
            return String.format("%.2f EB", (double) size / (1024L * 1024 * 1024 * 1024));
    }
}

Related

  1. formatSize(long size)
  2. formatSize(long size)
  3. formatSize(long size)
  4. formatSize(long size)
  5. formatSize(long size)
  6. formatSize(long size)
  7. formatSize(long size)
  8. formatSize(Long size)
  9. formatSize(long size)