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

private static long getDirSize(File dir) {

    long size = 0;
    if (!dir.exists()) {
        dir.mkdir();/*  w ww.  j  a  va  2  s. c  om*/
    }
    File[] files = dir.listFiles();

    for (File file : files) {
        if (file.isFile()) {
            size += file.length();
        }
    }

    return size;
}

From source file:Main.java

/**
 * return all the files contained in the specified directory
 *///from  ww w.  j  ava2 s.c  o m
public static void fileList(String directoryName, ArrayList<File> files) {
    File directory = new File(directoryName);

    // get all the files from a directory
    File[] fList = directory.listFiles();
    for (File file : fList) {
        if (file.isFile()) {
            files.add(file);
        } else if (file.isDirectory()) {
            fileList(file.getAbsolutePath(), files);
        }
    }
}

From source file:Main.java

public static void delFile(String fileName) {
    File file = new File(SDPATH + fileName);
    if (file.isFile()) {
        file.delete();/*  w ww . j  ava 2 s  . co m*/
    }
    file.exists();
}

From source file:Main.java

public static void delFile(String fileName) {
    File file = new File(SD_PATH + fileName);
    if (file.isFile()) {
        file.delete();//from  w  w w  .j  a v  a2 s  .c  o  m
    }
    file.exists();
}

From source file:Main.java

public static boolean isFileExist(String path) {
    if (TextUtils.isEmpty(path))
        return false;
    File file = new File(path);
    return file.exists() && file.isFile();
}

From source file:Main.java

public static void writeFile(File f, byte[] bS) throws Exception {

    if (f.isFile() && f.exists()) {
        f.delete();// ww w.  java  2  s.  c  o m
    }

    FileOutputStream fos = new FileOutputStream(f);
    fos.write(bS, 0, bS.length);
    fos.flush();
    fos.close();
}

From source file:Main.java

public static String getFileMD5(File file) {
    if (!file.isFile()) {
        return null;
    }//  w ww.  ja va2s  . c om
    MessageDigest digest = null;
    FileInputStream in = null;
    byte buffer[] = new byte[1024];
    int len;
    try {
        digest = MessageDigest.getInstance("MD5");
        in = new FileInputStream(file);
        while ((len = in.read(buffer, 0, 1024)) != -1) {
            digest.update(buffer, 0, len);
        }
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    BigInteger bigInt = new BigInteger(1, digest.digest());
    return bigInt.toString(16);
}

From source file:Main.java

public static List<File> getFiles(Context context, String ext) {
    File dir = context.getFilesDir();
    final List<File> files = new ArrayList<File>();
    File[] subFiles = dir.listFiles();
    if (subFiles != null) {
        for (File file : subFiles) {
            if (file.isFile() && file.getName().endsWith(ext)) {
                files.add(file);//ww w.j a  v a2 s  . co  m
            }
        }
    }
    return files;
}

From source file:Main.java

public static boolean isFile(File file) {
    return file.exists() && file.isFile();
}

From source file:Main.java

public static void deleteDir() {
    File dir = new File(SD_PATH);
    if (!dir.exists() || !dir.isDirectory())
        return;/*from   w w  w. j  a va 2s.  com*/

    for (File file : dir.listFiles()) {
        if (file.isFile())
            file.delete();
        else if (file.isDirectory())
            deleteDir();
    }
    dir.delete();
}