Here you can find the source of getFileSize(File element)
public static String getFileSize(File element)
//package com.java2s; /******************************************************************************* * Copyright (c) 2009-2013 SKRATCHDOT.COM * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * http://www.eclipse.org/legal/epl-v10.html * /*from ww w. j a v a 2s. co m*/ * Contributors: * JEFF |:at:| SKRATCHDOT |:dot:| COM *******************************************************************************/ import java.io.File; import java.text.NumberFormat; public class Main { private static final NumberFormat numberFormat = NumberFormat.getNumberInstance(); public static String getFileSize(File element) { if (element.isDirectory()) { return ""; } else { long filesizeInKb = ((element.length() + 512) / 1024); return "" + numberFormat.format(filesizeInKb) + " KB"; } } }