Check if directory is empty

Because having something like Directory.isEmpty() would be too obvious.

File dir = new File("path/to/my/file");
boolean isEmpty = file.isDirectory() && file.list().length == 0

Create a Path to Nonexistent Temporary file

This is an interesting task. I needed to create a path to a temporary zip archive that did not exist yet so that I could use a zip4j library. It is easy to create a temporary file.

1 File tempFile = File.createTempFile("file-download", ".zip", tempDirectory);
2 ZipParameters zipParameters = new ZipParameters();
3 zipParameters.setCompressionLevel(CompressionLevel.MAXIMUM);
4 ZipFile archive = new ZipFile(tempFile.getAbsolutePath()); 1
5 archive.addFile(syslog);

The problem is with <1>: When the file already exists, ZipFile assumes that it is a zip archive and tries to approach it in such manner and it dies on exception since the tempFile is empty.

So how to create a path to a temporary file without actually creating the file itself?

Hacky way: Create a file and delete it immediately
File tempFile = File.createTempFile("file-download", ".zip", tempDirectory);
tempFile.delete()

This works but it is stupid, there is a side-effect of deleting a file which was previously unnecessarily created. There must be a better way.

Better way: ???
 // TBD