Java File Size Readable Format getReadableFileSize(long size)

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

Description

get Readable File Size

License

Open Source License

Declaration

public static String getReadableFileSize(long size) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.DecimalFormat;

public class Main {
    public static String getReadableFileSize(long size) {
        if (size <= 0)
            return "0";
        final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
        int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
        return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
    }/*from ww  w. j  a va2s.c o m*/
}

Related

  1. getFileSizeInBytes(File f)
  2. getFileSizeInMB(String fileName)
  3. getHumanSize(File dir)
  4. getReadableFileSize(int size)
  5. getReadableFileSize(long fileSizeInBytes)
  6. getReadableFileSize(long size, boolean abbreviation)
  7. toHuman(Double n)
  8. toHumanReadableByteCount(final long bytes)
  9. toHumanReadableFileSize(long fileSize)