List of utility methods to do File Size Readable Format
long | getFileSizeInByte(File file) get File Size In Byte return file.length();
|
long | getFileSizeInBytes(File f) get File Size In Bytes long size = 0; if (f.isFile()) { size = f.length(); } else if (f.isDirectory()) { File[] files = f.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isFile()) { size += files[i].length(); ... |
float | getFileSizeInMB(String fileName) get File Size In MB float ret = getFileSizeInBytes(fileName); ret = ret / (float) (1024 * 1024); return ret; |
String | getHumanSize(File dir) get Human Size return getHumanSize(getSize(dir));
|
String | getReadableFileSize(int size) Get the file size in a human-readable string. final int BYTES_IN_KILOBYTES = 1024; final DecimalFormat dec = new DecimalFormat("###.#"); final String KILOBYTES = " KB"; final String MEGABYTES = " MB"; final String GIGABYTES = " GB"; float fileSize = 0; String suffix = KILOBYTES; if (size > BYTES_IN_KILOBYTES) { ... |
String | getReadableFileSize(long fileSizeInBytes) Returns a human readable representation of a filesize given in bytes if (fileSizeInBytes <= 0) { return "0"; int digitGroups = (int) (Math.log10(fileSizeInBytes) / Math.log10(1024)); return new DecimalFormat("#,##0.#").format(fileSizeInBytes / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; |
String | getReadableFileSize(long size) get Readable 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 | getReadableFileSize(long size, boolean abbreviation) Format filesize to human readable format Get size in bytes e.g. if (size <= 0) { return "0B"; String[] units = abbreviation ? new String[] { "B", "kB", "MB", "GB", "TB" } : new String[] { "Bytes", "Kilobytes", "Megabytes", "Gigabytes", "Terabytes" }; int unit = (int) (Math.log10(size) / Math.log10(1024)); return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, unit)) + " " + units[unit]; |
String | toHuman(Double n) prints large numbers as KB, MB, GB or TB if (n == null) return null; String u = "B"; if (n > 1024) { n /= 1024; u = "KB"; if (n > 1024) { ... |
String | toHumanReadableByteCount(final long bytes) Returns a human-readable version of the given byte count. double value = bytes; int i = 0; for (; Math.abs(value) > BYTE_FAC && i < BYTE_UNITS.length; ++i) { value /= BYTE_FAC; return ((long) value) + " " + BYTE_UNITS[i]; |