Java File Size Get getFileSizeFormat(String total_size)

Here you can find the source of getFileSizeFormat(String total_size)

Description

getFileSizeFormat()

License

Open Source License

Declaration

public static String getFileSizeFormat(String total_size) 

Method Source Code

//package com.java2s;

import java.text.*;

public class Main {

    public static String getFileSizeFormat(String total_size) {

        double file_size = Double.parseDouble(total_size);
        String file_size_nm = "";

        DecimalFormat f2 = new DecimalFormat("0.00");
        if (1023 < file_size) {
            file_size = file_size / 1024;
            file_size_nm = f2.format(file_size) + "KB";
        } else {//  ww  w.jav  a  2 s  .c  o  m
            file_size_nm = file_size + "byte";
        }
        if (1023 < file_size) {
            file_size = file_size / 1024;
            file_size_nm = f2.format(file_size) + "MB";
        }
        if (1023 < file_size) {
            file_size = file_size / 1024;
            file_size_nm = f2.format(file_size) + "GB";
        }
        if (1023 < file_size) {
            file_size = file_size / 1024;
            file_size_nm = f2.format(file_size) + "TB";
        }

        return file_size_nm;
    }
}

Related

  1. getFileSize(String path)
  2. getFilesize(String path)
  3. getFileSize2(String filename)
  4. getFileSizeAggregate(String[] files)
  5. getFileSizeFormat(double inputvalue)
  6. getFileSizeLabel(long sizeInBytes)
  7. getFileSizeRecursive(File file, boolean subFolders)
  8. getFileSizes(File f)
  9. getFileSizeString(File file, boolean si)