Android File Size get fileLength(String filePath)

Here you can find the source of fileLength(String filePath)

Description

file Length

Declaration

public static String fileLength(String filePath) 

Method Source Code

//package com.java2s;
import java.io.File;
import java.text.DecimalFormat;

public class Main {

    public static String fileLength(String filePath) {
        return fileLength(new File(filePath).length());
    }// w  w  w. jav a 2  s.  co  m

    public static String fileLength(long 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";
        } else {
            lenStr = formater.format(length / (1024 * 1024 * 1024)) + " GB";
        }
        return lenStr;
    }
}

Related

  1. sizeOf(File file)
  2. getFileSize(File file)
  3. getFileSize(File f)
  4. getFileSizes(File f)
  5. fileLength(long length)
  6. getFileLength(String path)
  7. getFileSize(long fileSize)