We use cookies to collect and analyze information on site performance and usage,
to provide social media features and to enhance and customize content and advertisements.
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
public class FileUtils {
public static void main(String[] args) throws IOException {
//String folder = "c:/temp";
String folder = "c:/temp/foo";
System.out.println
("Folder " + folder + " empty ? " + FileUtils.isDirectoryEmpty(folder) );
}
public static Boolean isDirectoryEmpty(String directoryName) throws IOException {
File [] content =
new File(directoryName).listFiles
(new FilenameFilter() {
public boolean accept(File f, String s) {
return true; // accept anything
}});
if (content == null) {
throw new IOException(directoryName + " is not found.");
}
return (content.length == 0);
}
}