Here you can find the source of getFileSize(String filePath)
public static long getFileSize(String filePath)
//package com.java2s; //License from project: Apache License import java.io.File; public class Main { public static long getFileSize(String filePath) { long size = 0; File file = new File(filePath); if (file != null && file.exists()) { size = file.length();//from www . java 2s. co m } return size; } public static String getFileSize(long size) { if (size <= 0) return "0"; java.text.DecimalFormat df = new java.text.DecimalFormat("##.##"); float temp = (float) size / 1024; if (temp >= 1024) { return df.format(temp / 1024) + "M"; } else { return df.format(temp) + "K"; } } }