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

longgetFileSize(File file)
get File Size
return Long.parseLong(file.length() + "");
longgetFileSize(File file)
get File Size
return getFileSize(file, null);
longgetFileSize(File file)
get File Size
if (file.isDirectory()) {
    long foldersize = 0;
    File[] filelist = file.listFiles();
    for (int i = 0; i < filelist.length; i++) {
        foldersize += getFileSize(filelist[i]);
    return foldersize;
} else {
...
longgetFileSize(File file)
get File Size
long fileSize = 0;
if (file.exists()) {
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        for (int i = 0; i < files.length; i++) {
            fileSize += getFileSize(files[i]);
    } else {
...
longgetFileSize(File file)
Method for computing the size of a file or folder
if (file == null)
    return 0L;
if (file.isFile())
    return file.length();
if (!file.isDirectory())
    return 0L;
File[] subFiles = file.listFiles();
if (subFiles == null)
...
longgetFileSize(File file)
get File Size
if (!file.exists()) {
    return 0L;
if (file.isDirectory()) {
    long size = 0L;
    for (File subfile : listFiles(file)) {
        size += getFileSize(subfile);
    return size;
return file.length();
StringgetFileSize(File file)
get File Size
return getFormatSize(file.length());
longgetFileSize(File file)
Returns file size.
if (file.exists()) {
    return file.length();
} else {
    return 0;
longgetFileSize(File[] files)
Calculate the size of files
long num = 0L;
for (File file : files) {
    if (file.isDirectory()) {
        num += getFileSize(file.listFiles());
    } else {
        num += file.length();
return num;
longgetFileSize(final String filename)
GetFileSize - returns the file size
File f;
try {
    f = new File(filename);
    if (f.exists()) {
        return f.length();
} catch (final Exception e) {
return -1;