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

public static void deleteDirectory(File file) {
    if (file.isFile()) {
        file.delete();/*from  ww w.  j  a  v a 2  s .  c  o m*/
        return;
    }

    if (file.isDirectory()) {
        File[] childFiles = file.listFiles();
        if (childFiles == null || childFiles.length == 0) {
            file.delete();
            return;
        }

        for (int i = 0; i < childFiles.length; i++) {
            deleteDirectory(childFiles[i]);
        }
        file.delete();
    }
}

From source file:Main.java

public static void delete(File file) {
    if (file.isFile()) {
        file.delete();/*w w w.  j a v a2 s.  c o  m*/
        return;
    }

    if (file.isDirectory()) {
        File[] childFiles = file.listFiles();
        if (childFiles == null || childFiles.length == 0) {
            file.delete();
            return;
        }

        for (int i = 0; i < childFiles.length; i++) {
            delete(childFiles[i]);
        }
        file.delete();
    }
}

From source file:Main.java

public static boolean deleteDestFile(String sPath) {
    boolean flag = false;
    File file = new File(sPath);
    if (file.isFile() && file.exists()) {
        if (file.delete()) {
            flag = true;//from   ww  w.  java  2  s.  com
        } else {
            flag = true;
        }
    }
    return flag;
}

From source file:Main.java

private static void deleteFileOrDirectory(File file) {
    if (file.isDirectory()) {
        File[] subFiles = file.listFiles();
        for (File sf : subFiles) {
            if (sf.isFile())
                sf.delete();//from   w  w  w  . ja v  a  2  s  . co  m
            else
                deleteFileOrDirectory(sf);
        }
    }
    file.delete();
}

From source file:Main.java

public static int getNumOfFiles(String dirPath) {
    File dir = new File(dirPath);
    if (!dir.isDirectory()) {
        return 0;
    }// w w w  .  j a va  2s  . c o m

    File[] files = dir.listFiles();
    int numOfFiles = 0;
    for (File f : files) {
        if (f.isFile()) {
            numOfFiles++;
        }
    }

    return numOfFiles;
}

From source file:Main.java

static private List<File> getFiles(String src) {
    List<File> list = new ArrayList<File>();
    File f = new File(src);
    File files[] = f.listFiles();
    for (File file : files) {
        if (file.isFile()) {
            list.add(file);//w  w w  . ja v a  2 s . c  o m
        } else {
            list.addAll(getFiles(file.getPath()));
        }
    }
    return list;
}

From source file:Main.java

public static List<String> getAllFileLists(String dir) {
    List<String> results = new ArrayList<String>();

    File[] files = new File(dir).listFiles();
    //If this pathname does not denote a directory, then listFiles() returns null.

    for (File file : files) {
        if (file.isFile()) {
            results.add(file.getName());
        }//w  w  w.  j  av a  2  s.  co m
    }
    return results;
}

From source file:Main.java

private static void deleteFileOrDirectory(File file) {
    if (file.isDirectory()) {
        File[] subFiles = file.listFiles();
        for (File sf : subFiles) {
            if (sf.isFile()) {
                sf.delete();/* w  w w  .ja  va 2  s .c  o m*/
            } else {
                deleteFileOrDirectory(sf);
            }
        }
    }
    file.delete();
}

From source file:Main.java

private static void deleteCacheFile(File file) {
    if (file.isFile()) {
        file.delete();/*from  www .  jav  a  2 s .  co  m*/
    } else {
        File[] files = file.listFiles();
        for (File f : files) {
            deleteCacheFile(f);
        }
    }
}

From source file:Main.java

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