Android Utililty Methods File Size Readable Format

List of utility methods to do File Size Readable Format

Description

The list of methods to do File Size Readable Format are organized into topic(s).

Method

doublegetSizeInKbytes(final File path)
Gets the size of the path in kbytes.
return getSize(path) / ONE_KB_BYTES;
doublegetSizeInMegabytes(final File path)
Gets the size of the path in megabytes.
return getSize(path) / (ONE_KB_BYTES * ONE_KB_BYTES);
StringformatFileSize(long fileLength)
format File Size
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";
...
StringfileSizeFormat(long length)
file Size Format
return fileSizeFormat(length, 0);
StringfileSizeFormat(long length, int lev)
file Size Format
if (length > 1024 && lev < 6) {
    return fileSizeFormat(length / 1024, lev + 1);
} else {
    switch (lev) {
    case 0:
        return "" + length;
    case 1:
        return length + "K";
...
StringFormetFileSize(long fileS)
Formet File Size
DecimalFormat df = new DecimalFormat("#0.00");
String fileSizeString = "";
if (fileS < 1024) {
    fileSizeString = df.format((double) fileS) + "B";
} else if (fileS < 1048576) {
    fileSizeString = df.format((double) fileS / 1024) + "K";
} else if (fileS < 1073741824) {
    fileSizeString = df.format((double) fileS / 1048576) + "M";
...