Java File Size Get getFileSize(long fileSize)

Here you can find the source of getFileSize(long fileSize)

Description

get File Size

License

Open Source License

Declaration

public static String getFileSize(long fileSize) 

Method Source Code

//package com.java2s;

import java.text.DecimalFormat;

public class Main {
    public static String getFileSize(long fileSize) {
        String fileSizeStr = "";
        DecimalFormat df = new DecimalFormat("#.0");
        if (fileSize < 1024) {
            fileSizeStr = df.format((double) fileSize) + "B";
        } else if (fileSize < 1048576) {
            fileSizeStr = df.format((double) fileSize / 1024) + "K";
        } else if (fileSize < 1073741824) {
            fileSizeStr = df.format((double) fileSize / 1048576) + "M";
        } else {//from  w ww .ja v a 2s . c o m
            fileSizeStr = df.format((double) fileSize / 1073741824) + "G";
        }
        return fileSizeStr;
    }
}

Related

  1. getFileSize(final String filename)
  2. getFileSize(final String filePath)
  3. getFileSize(final String path)
  4. getFileSize(InputStream inputStream)
  5. getFileSize(int fileSize)
  6. getFilesize(String address)
  7. getFileSize(String fileName)
  8. getFileSize(String filename)
  9. getFileSize(String filename)