Java File Size Get getFileKBSize(long fsize)

Here you can find the source of getFileKBSize(long fsize)

Description

Retrieves the file size with KB format

License

Open Source License

Parameter

Parameter Description
fsize file size

Return

xxx,xxx KB

Declaration

public static String getFileKBSize(long fsize) 

Method Source Code

//package com.java2s;

import java.text.NumberFormat;

public class Main {
    /**/* ww  w. j a v  a  2s . c o  m*/
     * Retrieves the file size with KB format
     * 
     * @param fsize file size
     * @return xxx,xxx KB
     */
    public static String getFileKBSize(long fsize) {
        if (fsize < 0) {
            throw new IllegalArgumentException("File size can't be nagetive.");
        }
        long size = fsize / 1000;
        long li = fsize % 1000;
        if (li > 0) {
            size++;
        }
        return NumberFormat.getInstance().format(size) + " KB";
    }
}

Related

  1. countFileDisplaySize(long size)
  2. countFileSize(String pathname)
  3. fileSizeString(long bytes)
  4. getFileSize(@Nonnull File file)
  5. getFileSize(File dir)
  6. getFileSize(File element)
  7. getFileSize(File f)