Android File Size get fileLength(long length)

Here you can find the source of fileLength(long length)

Description

file Length

Declaration

public static String fileLength(long length) 

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. j a  va2s  . 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(String filePath)
  6. getFileLength(String path)
  7. getFileSize(long fileSize)