// 2) then quickly delete the file and...
// 3) convert it to a directory
File tmpDir = File.createTempFile(prefix, suffix, parentDirectory); // create file with unique name
boolean deleteOk = tmpDir.delete(); // delete the tmp file and...
boolean mkdirsOk = tmpDir.mkdirs(); // ...convert it to a directory
if (!deleteOk || !mkdirsOk) {
throw new IOException("Failed to create temp directory named [" + tmpDir + "]");
}