Here you can find the source of fileLength(String filePath)
public static String fileLength(String filePath)
//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; } }