Java File Size Readable Format formatFileSize(long bytes)

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

Description

format File Size

License

Apache License

Declaration

public static String formatFileSize(long bytes) 

Method Source Code

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

public class Main {
    public static String formatFileSize(long bytes) {
        if (bytes < 4096) {
            return bytes + " bytes";
        } else if (bytes < 1024 * 1024) {
            return (Math.round(10 * bytes / 1024) / 10) + " kb";
        } else {/* w w w. j  ava2  s .  co  m*/
            return (Math.round(10 * bytes / (1024 * 1024)) / 10) + " mb";
        }
    }
}

Related

  1. formatByteSize(long byteSize)
  2. formatByteSizeToString(long bytes)
  3. formatDataSize(long size)
  4. FormatDataSize(long uBytes)
  5. FormatDataSizeKB(long uBytes)
  6. formatFileSize(long bytes, boolean si)
  7. formatFileSize(long fileSize)
  8. formatFileSize(long fileSize)
  9. formatFileSize(long fileSize)