Android File Size Readable Format formatFileSize(long fileLength)

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

Description

format File Size

Declaration

public static String formatFileSize(long fileLength) 

Method Source Code

//package com.java2s;

import java.text.DecimalFormat;

public class Main {

    public static String formatFileSize(long fileLength) {
        DecimalFormat df = new DecimalFormat("#.00");
        String fileSizeStr = "";
        if (fileLength < 1024)
            fileSizeStr = df.format((double) fileLength) + "B";
        else if (fileLength < 1048576)
            fileSizeStr = df.format((double) fileLength / 1024) + "KB";
        else if (fileLength < 1073741824)
            fileSizeStr = df.format((double) fileLength / 1048576) + "MB";
        else//from   w  w  w  .  j  ava2 s .c om
            fileSizeStr = df.format((double) fileLength / 1073741824)
                    + "GB";
        return fileSizeStr;
    }
}

Related

  1. getSizeInKbytes(final File path)
  2. getSizeInMegabytes(final File path)
  3. fileSizeFormat(long length)
  4. fileSizeFormat(long length, int lev)
  5. FormetFileSize(long fileS)