List of utility methods to do File Size Readable Format
String | FormatDataSizeKB(long uBytes) Format Data Size KB final long uKB = 1024; if (uBytes == 0) return "0 KB"; if (uBytes <= uKB) return "1 KB"; return (((uBytes - 1L) / uKB) + 1L) + " KB"; |
String | formatFileSize(long bytes) format File Size if (bytes < 4096) { return bytes + " bytes"; } else if (bytes < 1024 * 1024) { return (Math.round(10 * bytes / 1024) / 10) + " kb"; } else { return (Math.round(10 * bytes / (1024 * 1024)) / 10) + " mb"; |
String | formatFileSize(long bytes, boolean si) format File Size int unit = si ? 1000 : 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); |
String | formatFileSize(long fileSize) Formats fileSize (in byte) in B/KB/MB/GB String unit = "B"; double size = 0; if (fileSize < 1024) { unit = "B"; size = (double) fileSize; } else if (fileSize < (1024 * 1024L)) { unit = "KB"; size = (double) fileSize / (1024L); ... |
String | formatFileSize(long fileSize) Formats a file size as a string (Kb). long size = fileSize / 1024; return String.valueOf(size); |
String | formatFileSize(long fileSize) format File Size String suffix = null; if (fileSize < 1024L) suffix = "B"; else if (fileSize < 0x100000L) { fileSize = Math.round(fileSize / 1024L); suffix = "KB"; } else { fileSize = Math.round((fileSize / 0x100000L) * 100L) / 100; ... |
String | formatFileSize(long fileSizeLong) format File Size double fileSize = fileSizeLong; if (fileSize < 1024) { return String.format("%d bytes", fileSizeLong); fileSize /= 1024; if (fileSize < 1024) { return String.format("%.2f KB", fileSize); fileSize /= 1024; return String.format("%.2f MB", fileSize); |
String | formatFileSize(long size) Formats a file size to a printable string. float value = size; String unit; if (size > 1000000) { value /= 1048576; unit = " MiB"; } else if (size > 2000) { value /= 1024; unit = " KiB"; ... |
String | formatFileSize(long size) Formats file size, applying KB, MB, GB units. if (size == 0) { return "0"; if (size < 1024) { return size + "B"; if (size >= 1024 && size < 1048576) { return Math.round((size / 1024) * 100.0) / 100.0 + "KB"; ... |
String | formatFileSize(long size, String format) 1204,K => 1K if (format.equals("K")) { return size / 1024.0 + "K"; if (format.equals("M")) { return size / 1024.0 / 1024.0 + "M"; if (format.equals("G")) { return size / 1024.0 / 1024.0 / 1024.0 + "G"; ... |