Java File Size Get getFileSize(File element)

Here you can find the source of getFileSize(File element)

Description

get File Size

License

Open Source License

Declaration

public static String getFileSize(File element) 

Method Source Code

//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";
        }
    }
}

Related

  1. countFileSize(String pathname)
  2. fileSizeString(long bytes)
  3. getFileKBSize(long fsize)
  4. getFileSize(@Nonnull File file)
  5. getFileSize(File dir)
  6. getFileSize(File f)
  7. getFileSize(File file)
  8. getFileSize(File file)
  9. getFileSize(File file)