Example usage for java.io File length

List of usage examples for java.io File length

Introduction

In this page you can find the example usage for java.io File length.

Prototype

public long length() 

Source Link

Document

Returns the length of the file denoted by this abstract pathname.

Usage

From source file:Main.java

private static void cleanDir(File dir, long bytes) {
    long bytesDeleted = 0;
    File[] files = dir.listFiles();

    for (File file : files) {
        bytesDeleted += file.length();
        file.delete();//from   w w  w .  j a  va2s.  c o  m

        if (bytesDeleted >= bytes) {
            break;
        }
    }
}

From source file:Main.java

public static boolean isFileExist(String filePath, int fileSize) {
    File file = new File(filePath);
    return file.exists() && file.length() == fileSize;
}

From source file:Main.java

private static boolean testCleanNeeded(File[] files, long triggerSize) {

    long total = 0;

    for (File f : files) {
        total += f.length();
        if (total > triggerSize) {
            return true;
        }/*from   w w  w .j av a 2 s  .c om*/
    }

    return false;
}

From source file:Main.java

public final static boolean isEmptyOrNotExists(final String file) {
    File f = new File(file);
    return !f.isFile() || (f.length() == 0);
}

From source file:Main.java

public static long getTotalSizeOfFilesInDir(final File file) {
    if (file.isFile())
        return file.length();
    final File[] children = file.listFiles();
    long total = 0;
    if (children != null)
        for (final File child : children)
            total += getTotalSizeOfFilesInDir(child);
    return total;
}

From source file:Main.java

public static int getFolderSize(String relativePath) {
    int fileLength = 0;
    //      File dir = new File(path);
    File dir = creatSDDir(relativePath);
    if (dir.isDirectory()) {
        File[] files = dir.listFiles();
        for (File file : files) {
            fileLength += file.length();
        }//from  w  w  w. ja  v a 2s.com
    } else {
        return -1;
    }
    return fileLength / 1024;
}

From source file:Main.java

public static long getFileSize(File file) {
    if (file.exists() && file.isFile()) {
        return file.length();
    }/*from www.  ja  v a2s.c  om*/
    return 0;
}

From source file:Main.java

/**
 * Returns the size of the given file in bytes.
 *
 * @author Ian Copland//from w w  w  .j  av  a2 s.co  m
 *
 * @param in_filePath - The path to the file which is to have its size calculated.
 *
 * @return The size of the file in bytes.
 */
public static long getFileSize(String in_filePath) {
    File file = new File(in_filePath);
    return file.length();
}

From source file:Main.java

public static long getFileSize(String path) {
    if (TextUtils.isEmpty(path)) {
        return -1;
    }/*from  w  ww . j a va  2 s .co m*/
    File file = new File(path);
    return (file.exists() && file.isFile() ? file.length() : -1);
}

From source file:Main.java

/**
 * install app/*w  ww.ja v  a2  s .c  om*/
 * 
 * @param context
 * @param filePath
 * @return whether apk exist
 */
public static boolean install(Context context, String filePath) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    File file = new File(filePath);
    if (file != null && file.length() > 0 && file.exists() && file.isFile()) {
        i.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
        return true;
    }
    return false;
}