List of utility methods to do File Size Readable Format
String | toHumanReadableFileSize(long fileSize) transforms the given file size in bytes into a human readable string like "15 MB" or "256 KB" for (int i = FILE_SIZE_NAMES.length - 1; i > 0; --i) { float thisValue = (float) Math.pow(1024, i); if (fileSize / thisValue > 1) { return String.format("%3.2f %s", fileSize / thisValue, FILE_SIZE_NAMES[i]); return "0"; |
String | toHumanReadableSize(final long bytes) Returns a human readable value in storage units rounded up to two decimal places. if (bytes < BASE) { return bytes + " B"; final int baseValue = (63 - Long.numberOfLeadingZeros(bytes)) / 10; return String.format("%.2f %sB", (double) bytes / (1L << (baseValue * 10)), " kMGTPE".charAt(baseValue)); |