Java Utililty Methods File Size Get

List of utility methods to do File Size Get

Description

The list of methods to do File Size Get are organized into topic(s).

Method

StringcountFileDisplaySize(long size)
count File Display Size
String displaySize;
if (size / ONE_GB > 0) {
    displaySize = format(Math.floor(size * 100.0 / ONE_GB) / 100) + "G";
} else if (size / ONE_MB > 0) {
    displaySize = format(Math.floor(size * 100.0 / ONE_MB) / 100) + "M";
} else if (size / ONE_KB > 0) {
    displaySize = format(Math.floor(size * 100.0 / ONE_KB) / 100) + "K";
} else {
...
StringcountFileSize(String pathname)
count File Size
String fileSizeString = "";
try {
    File file = new File(pathname);
    DecimalFormat df = new DecimalFormat("#.00");
    long fileS = file.length();
    if (fileS < 1024) {
        fileSizeString = "0byte";
    } else if (fileS < 1048576) {
...
StringfileSizeString(long bytes)
file Size String
ensureFormat();
final StringBuffer result = new StringBuffer(64);
double value;
if (bytes >= ONE_GB) {
    value = scaleToThreeDecimals(bytes, ONE_GB);
    result.append(format.format(value));
    result.append(" GB");
} else if (bytes >= ONE_MB) {
...
StringgetFileKBSize(long fsize)
Retrieves the file size with KB format
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";
longgetFileSize(@Nonnull File file)
get File Size
if (!file.exists()) {
    return -1L;
long size = 0;
if (file.isDirectory()) {
    File[] files = file.listFiles();
    if (files != null && files.length > 0) {
        for (File f : files) {
...
longgetFileSize(File dir)
Get size of the file
long size = 0;
if (dir.isFile()) {
    size = dir.length();
} else {
    File[] subFiles = dir.listFiles();
    for (File file : subFiles) {
        if (file.isFile()) {
            size += file.length();
...
StringgetFileSize(File element)
get File Size
if (element.isDirectory()) {
    return "";
} else {
    long filesizeInKb = ((element.length() + 512) / 1024);
    return "" + numberFormat.format(filesizeInKb) + " KB";
longgetFileSize(File f)
get File Size
long s = 0;
if (f.exists()) {
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(f);
        s = fis.available();
    } catch (Exception e) {
        e.printStackTrace();
...
StringgetFileSize(File file)
get File Size
String size;
long bytes = file.length();
if (bytes == 0) {
    size = "";
} else if (bytes < 1024) {
    size = bytes + "b";
} else {
    float kb = bytes / 1024F;
...
longgetFileSize(File file)
get File Size
return file.length();