Android Utililty Methods File Size get

List of utility methods to do File Size get

Description

The list of methods to do File Size get are organized into topic(s).

Method

longsizeOf(File file)
size Of
if (!file.exists()) {
    throw new IllegalArgumentException(file + " does not exist");
if (file.isDirectory()) {
    return sizeOfDirectory(file);
} else {
    return file.length();
longgetFileSize(File file)
Returns file size.
if (file.exists()) {
    return file.length();
} else {
    return 0;
longgetFileSize(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;
longgetFileSizes(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;
StringfileLength(String filePath)
file Length
return fileLength(new File(filePath).length());
StringfileLength(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";
...
LonggetFileLength(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;
StringgetFileSize(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);
...