FileDocCategorySizeDatePackage
EmptyFileFilter.javaAPI DocAndroid 1.5 API2749Wed May 06 22:42:46 BST 2009org.apache.commons.io.filefilter

EmptyFileFilter

public class EmptyFileFilter extends AbstractFileFilter implements Serializable
This filter accepts files or directories that are empty.

If the File is a directory it checks that it contains no files.

Example, showing how to print out a list of the current directory's empty files/directories:

File dir = new File(".");
String[] files = dir.list( EmptyFileFilter.EMPTY );
for ( int i = 0; i < files.length; i++ ) {
System.out.println(files[i]);
}

Example, showing how to print out a list of the current directory's non-empty files/directories:

File dir = new File(".");
String[] files = dir.list( EmptyFileFilter.NOT_EMPTY );
for ( int i = 0; i < files.length; i++ ) {
System.out.println(files[i]);
}
since
Commons IO 1.3
version
$Revision: 587916 $

Fields Summary
public static final IOFileFilter
EMPTY
Singleton instance of empty filter
public static final IOFileFilter
NOT_EMPTY
Singleton instance of not-empty filter
Constructors Summary
protected EmptyFileFilter()
Restrictive consructor.

    
           
      
    
Methods Summary
public booleanaccept(java.io.File file)
Checks to see if the file is empty.

param
file the file or directory to check
return
true if the file or directory is empty, otherwise false.

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