List of utility methods to do File Size get
long | sizeOf(File file) size Of if (!file.exists()) { throw new IllegalArgumentException(file + " does not exist"); if (file.isDirectory()) { return sizeOfDirectory(file); } else { return file.length(); |
long | getFileSize(File file) Returns file size. if (file.exists()) { return file.length(); } else { return 0; |
long | getFileSize(File f) get File Size long size = 0; File flist[] = f.listFiles(); for (int i = 0; i < flist.length; i++) { if (flist[i].isDirectory()) { size = size + getFileSize(flist[i]); } else { size = size + flist[i].length(); return size; |
long | getFileSizes(File f) get File Sizes long s = 0; if (f.exists()) { FileInputStream fis = null; fis = new FileInputStream(f); s = fis.available(); } else { f.createNewFile(); return s; |
String | fileLength(String filePath) file Length return fileLength(new File(filePath).length()); |
String | fileLength(long length) file Length String lenStr = null; DecimalFormat formater = new DecimalFormat("#0.##"); if (length < 1024) { lenStr = formater.format(length) + " Byte"; } else if (length < 1024 * 1024) { lenStr = formater.format(length / 1024.0f) + " KB"; } else if (length < 1024 * 1024 * 1024) { lenStr = formater.format(length / (1024 * 1024)) + " MB"; ... |
Long | getFileLength(String path) get File Length Long fileLength = null; try { FileInputStream in = new FileInputStream(path); File file = new File(path); fileLength = file.length(); } catch (FileNotFoundException e) { e.printStackTrace(); return fileLength; |
String | getFileSize(long fileSize) get File Size int freeUnit; for (freeUnit = 0; fileSize >= 100; freeUnit++) { fileSize /= 1024; DecimalFormat decFormat = new DecimalFormat("0.0"); String doubleString = decFormat.format(fileSize); StringBuffer buffer = new StringBuffer(); buffer.append(doubleString); ... |