Java Size Format formatFileSize(long fileS)

Here you can find the source of formatFileSize(long fileS)

Description

format File Size

License

Apache License

Declaration

public static String formatFileSize(long fileS) 

Method Source Code

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

public class Main {

    public static String formatFileSize(long fileS) {
        java.text.DecimalFormat df = new java.text.DecimalFormat("#.00");
        String fileSizeString = "";
        if (fileS < 1024) {
            fileSizeString = df.format((double) fileS) + "B";
        } else if (fileS < 1048576) {
            fileSizeString = df.format((double) fileS / 1024) + "KB";
        } else if (fileS < 1073741824) {
            fileSizeString = df.format((double) fileS / 1048576) + "MB";
        } else {/*www. j a  va2  s  .com*/
            fileSizeString = df.format((double) fileS / 1073741824) + "G";
        }
        return fileSizeString;
    }
}

Related

  1. formatDiskSize(final long diskSize)
  2. formatFileSize(double fileSize, int precision, int unit, boolean showUnit)
  3. formatFileSize(File file)
  4. formatFilesize(final long filesize, final Locale locale)
  5. formatFilesize(int s)
  6. formatFilesize(long filesize)
  7. formatFileSize(long fileSize, int decimalPos)
  8. formatFileSize(long length)
  9. formatFileSize(long size)