Java File Size Get getFilesizeString(long size)

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

Description

get Filesize String

License

Open Source License

Declaration

public static String getFilesizeString(long size) 

Method Source Code

//package com.java2s;

import java.text.DecimalFormat;

public class Main {

    public static String getFilesizeString(long size) {
        String tail = "";
        if (1024 > size) {
            tail = "byte";
        } else if (1048576 > size) {
            size = size / 1024;/*from  w ww .  j  a  va2 s  .  c  o m*/
            tail = "Kb";
        } else if (1073741824 > size) {
            size = size / 1024;
            tail = "Mb";
        } else if (1099511627776.0 > size) {
            size = (long) (size / 1073741824.0);
            tail = "Gb";
        }
        return new DecimalFormat("#,###.00").format(size) + tail;
    }
}

Related

  1. getFileSizeFormat(String total_size)
  2. getFileSizeLabel(long sizeInBytes)
  3. getFileSizeRecursive(File file, boolean subFolders)
  4. getFileSizes(File f)
  5. getFileSizeString(File file, boolean si)
  6. getFileSizeStringFor(File file)
  7. getFolderSize(File folder)
  8. getSize(long fileSize)
  9. getSizeErrorMessage(String pattern, Long maxFileSize, Long fileSize, String fileName)