Java File Size Get getFileSize(int fileSize)

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

Description

get File Size

License

Open Source License

Declaration

public static final String getFileSize(int fileSize) 

Method Source Code

//package com.java2s;

import java.text.DecimalFormat;

public class Main {

    public static final String getFileSize(int fileSize) {
        double result = fileSize;
        if (result < 1024) {
            return result + "B";
        }//from   ww w.  j a v a  2  s  .c o  m

        DecimalFormat df = new DecimalFormat("#0.00");

        result = result / 1024;
        if (result < 1024) {
            return df.format(result) + "KB";
        }

        result = result / 1024;
        if (result < 1024) {
            return df.format(result) + "MB";
        }

        result = result / 1024;
        if (result < 1024) {
            return df.format(result) + "GB";
        }

        result = result / 1024;
        return df.format(result) + "TB";
    }
}

Related

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