Example usage for java.io File isFile

List of usage examples for java.io File isFile

Introduction

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

Prototype

public boolean isFile() 

Source Link

Document

Tests whether the file denoted by this abstract pathname is a normal file.

Usage

From source file:Main.java

/**
 * Returns count of files contained recursively in the specified directory.
 * If the dir does not exist then it returns 0.
 *///from w w  w  .  j a  va  2  s  .  c  o  m
public static int count(File dir, FileFilter fileFilter, boolean includeFolders) {
    int result = 0;
    if (!dir.exists()) {
        return 0;
    }
    for (final File file : dir.listFiles()) {
        if (file.isFile() && !fileFilter.accept(file)) {
            continue;
        }
        if (file.isDirectory()) {
            if (includeFolders) {
                result++;
            }
            result = result + count(file, fileFilter, includeFolders);
        } else {
            result++;
        }
    }
    return result;
}

From source file:Main.java

public static boolean installApp(Context context, String filePath) {
    if (filePath != null && filePath.length() > 4
            && filePath.toLowerCase().substring(filePath.length() - 4).equals(".apk")) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        File file = new File(filePath);
        if (file.exists() && file.isFile() && file.length() > 0) {
            intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
            return true;
        }// w ww .j  av  a 2s  .  c o  m
    }
    return false;
}

From source file:Main.java

public static String readString(String path) {
    File file = new File(path);
    if (file.exists() && file.isFile()) {
        return readString(file);
    }/*from   w  ww  . j a  v  a  2  s .c om*/
    return null;

}

From source file:Main.java

/**
 0: number of files// www.  j a v  a2 s  .  c o  m
 1: total length
 2: number of directories
 */
public static void getDirSize(final File f, final long[] l) {
    if (f.isFile()) {
        l[0]++;
        l[1] += f.length();
    } else {
        Stack<File> stk = new Stack<>();
        stk.add(f);
        File fi = null;
        File[] fs;
        while (stk.size() > 0) {
            fi = stk.pop();
            fs = fi.listFiles();
            for (File f2 : fs) {
                if (f2.isDirectory()) {
                    stk.push(f2);
                    l[2]++;
                } else {
                    l[0]++;
                    l[1] += f2.length();
                }
            }
        }
    }
}

From source file:Main.java

public static boolean isNoMediaDir(File dir) {
    boolean result = false;
    if (dir == null || dir.isFile()) {
        result = true;/*from   w  w  w  .j  ava  2  s.c  o m*/
    } else {
        File[] files = dir.listFiles();
        if (files != null) {
            for (File childFile : files) {
                if (childFile.isFile() && ".nomedia".equals(childFile.getName())) {
                    result = true;
                    break;
                }
            }
        }
    }
    return result;
}

From source file:Main.java

public static boolean deleteAll(File dir) {
    String fileNames[] = dir.list();
    if (fileNames == null)
        return false;
    for (int i = 0; i < fileNames.length; i++) {
        File file = new File(dir, fileNames[i]);
        if (file.isFile())
            file.delete();//from   w  w w  .  j  a  v a 2  s  .c  om
        else if (file.isDirectory())
            deleteAll(file);
    }

    return dir.delete();
}

From source file:com.textocat.textokit.morph.opencorpora.resource.DictionaryDeserializer.java

public static MorphDictionaryImpl from(File file) throws Exception {
    if (!file.isFile()) {
        throw new IllegalArgumentException(String.format("%s is not existing file", file));
    }//from   w  ww.  j  ava2  s .  c o  m
    return from(new FileInputStream(file), file.toString());
}

From source file:Main.java

public static long folderSize(File directory) {
    long length = 0;
    try {// w  w  w.ja  v a  2s . c  om
        for (File file : directory.listFiles()) {

            if (file.isFile())
                length += file.length();
            else
                length += folderSize(file);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return length;
}

From source file:andrew.addons.NextFile.java

public static String nextFile(String filename) {
    int a = 1;/*from  ww  w.jav  a 2s .  c o m*/
    File file = new File(filename);
    while (file.exists() || file.isFile()) {
        file = new File(FilenameUtils.removeExtension(filename) + "(" + Integer.toString(a) + ")."
                + FilenameUtils.getExtension(filename));
        a++;
    }
    return file.getName();
}

From source file:Main.java

public static boolean installNormal(Context context, String filePath) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    File file = new File(filePath);
    if (file == null || !file.exists() || !file.isFile() || file.length() <= 0) {
        return false;
    } else {//from  w  ww  .j av a2s .c  o m
        intent.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
        return true;
    }
}