List of utility methods to do File Size Get
String | prettyFileSize(long size) pretty File Size if (size <= 0) return "0"; final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" }; int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; |
String | readableFileSize(final long size) readable File Size if (size < 0) return ""; if (size == 0) return "0.0"; final int digitGroup = (int) (Math.log10(size) / Math.log10(1024)); return DECIMAL_FORMAT.format(size / Math.pow(1024, digitGroup)) + " " + UNITS[digitGroup]; |
String | readableFileSize(long size) readable File Size if (size <= 0) return "0"; int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; |
String | readableFileSize(long size) readable File Size if (size <= 0) return "0 B"; int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)).replace(",", ".") + " " + UNITS[digitGroups]; |
String | stringifyFileSize(double value) stringify File Size double d; if (value >= TB) { d = value / TB; String val = df.format(d); return val + " TB"; } else if (value >= GB) { d = value / GB; String val = df.format(d); ... |
String | toFileSize(final long longSize, final int decimalPos) to File Size final NumberFormat fmt = NumberFormat.getNumberInstance(); if (decimalPos >= 0) { fmt.setMaximumFractionDigits(decimalPos); final double size = longSize; double val = size / (1024 * 1024); if (val > 1) { return fmt.format(val).concat(" MB"); ... |