Here you can find the source of deleteIfEmpty(final File directory)
public static final boolean deleteIfEmpty(final File directory) throws IOException
//package com.java2s; import java.io.File; import java.io.FileFilter; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; public class Main { public static final boolean deleteIfEmpty(final File directory) throws IOException { if (directory.list().length > 0) return false; Files.delete(directory.toPath()); return true; }/*from w w w. j ava2s .c o m*/ public static void delete(final File directory, final FileFilter fileFilter) throws IOException { if (!directory.exists() || !directory.isDirectory()) throw new FileNotFoundException("No directory found at " + directory); for (File file : directory.listFiles(fileFilter)) Files.delete(file.toPath()); } }