List of utility methods to do File Size Get
long | getFileSizes(File f) get File Sizes long s = 0; if (f.exists()) { FileInputStream fis = null; fis = new FileInputStream(f); s = fis.available(); return s; |
String | getFileSizeString(File file, boolean si) Get the formatted File size as a String See http://stackoverflow.com/questions/3758606/ for more information on how to properly format the size if (!file.isDirectory()) { long bytes = file.length(); 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 | getFilesizeString(long size) get Filesize String String tail = ""; if (1024 > size) { tail = "byte"; } else if (1048576 > size) { size = size / 1024; tail = "Kb"; } else if (1073741824 > size) { size = size / 1024; ... |
String | getFileSizeStringFor(File file) Returns a string representation of a file size, such as "842 bytes", "1.43 KB" or "3.4 MB". return getFileSizeStringFor(file.length(), false);
|
String | getFolderSize(File folder) get Folder Size if (folder == null) return ""; if (folder.isDirectory()) { return getFilesSize(folder.listFiles()); } else { return ""; |
String | getSize(long fileSize) get Size String size = getSize(fileSize, 2);
return size;
|
String | getSizeErrorMessage(String pattern, Long maxFileSize, Long fileSize, String fileName) get Size Error Message return MessageFormat.format(pattern, getHumanReadableByteCount(maxFileSize, false),
getHumanReadableByteCount(fileSize, false), fileName);
|
String | getStringSizeLengthFile(long size) get String Size Length File DecimalFormat df = new DecimalFormat("0.00"); float sizeKb = 1024.0f; float sizeMo = sizeKb * sizeKb; float sizeGo = sizeMo * sizeKb; float sizeTerra = sizeGo * sizeKb; if (size < sizeMo) return df.format(size / sizeKb) + " Kb"; else if (size < sizeGo) ... |
String | humanFileSize(Long longFileSize) Converts the size of a file to a human-readable string, e.g. if (longFileSize < 0) return (""); if (longFileSize < 512) return (longFileSize.toString()); double doubleBytes; DecimalFormat outputFormat = new DecimalFormat("0.00"); StringBuffer outputStrBuf = new StringBuffer(); FieldPosition fieldPos = new FieldPosition(0); ... |
String | humanReadableFileSize(long size) human Readable File Size if (size <= 0) { return "0"; final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" }; int magnitude = (int) (Math.log10(size) / Math.log10(1024)); return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, magnitude)) + " " + units[magnitude]; |