Jun 7, 2018

How To Check If Directory Is Empty In Java

You can check length of list() as following:
File file = new File("/i88.ca");
   //Directory is not empty
   //Directory is empty

With JDK >= 7 you can use Files.newDirectoryStream to open the directory and then use the iterator's hasNext() method to test there are any files to iterator over. This should work better for huge directories or where the directory is on a remote file system when compared to the java.io.File list methods.