List of utility methods to do File Size Get
String | getFileSize(final String filePath) get File Size String formattedFileSize = "0 B"; File fileReference = new File(filePath); if (fileReference.exists()) { long fileSizeInBytes = fileReference.length(); if (fileSizeInBytes < 1024) { return fileSizeInBytes + " B"; int unitIndex = (int) (Math.log(fileSizeInBytes) / Math.log(1024)); ... |
long | getFileSize(final String path) get File Size return getFileSize(getFile(path));
|
int | getFileSize(InputStream inputStream) get File Size int size = 0; try { size = inputStream.available(); } catch (IOException e) { e.printStackTrace(); return size; |
String | getFileSize(int fileSize) get File Size double result = fileSize; if (result < 1024) { return result + "B"; DecimalFormat df = new DecimalFormat("#0.00"); result = result / 1024; if (result < 1024) { return df.format(result) + "KB"; ... |
String | getFileSize(long fileSize) get File Size String fileSizeStr = ""; DecimalFormat df = new DecimalFormat("#.0"); if (fileSize < 1024) { fileSizeStr = df.format((double) fileSize) + "B"; } else if (fileSize < 1048576) { fileSizeStr = df.format((double) fileSize / 1024) + "K"; } else if (fileSize < 1073741824) { fileSizeStr = df.format((double) fileSize / 1048576) + "M"; ... |
long | getFilesize(String address) get Filesize File file = new File(address); if (file.exists()) { return file.length(); } else { return 0; |
long | getFileSize(String fileName) Get the size of a file. File file = new File(fileName); return file.length(); |
String | getFileSize(String filename) get File Size File file = new File(filename); return getReadableFileSize(file.length()); |
int | getFileSize(String filename) get File Size try { File fl = new File(filename); int length = (int) fl.length(); return length; } catch (Exception e) { return 0; |
long | getFileSize(String fileName, Logger log) get File Size File file = new File(fileName); if (!file.exists()) { if (log != null) log.log(Level.WARNING, "File \"" + fileName + "\" not found, so size is zero"); return 0; return file.length(); |