Here you can find the source of makeTempDirectory(String dirName, boolean deleteIfExists)
public static File makeTempDirectory(String dirName, boolean deleteIfExists) throws IOException
//package com.java2s; import java.io.*; public class Main { public static File makeTempDirectory(String dirName, boolean deleteIfExists) throws IOException { return makeTempDirectory(null, dirName, deleteIfExists); }// w w w . j a v a 2 s. c o m public static File makeTempDirectory(File parentTempDir, String dirName, boolean deleteIfExists) throws IOException { File dir = new File(getSystemTempDirectory(parentTempDir), dirName); if (dir.exists()) { if (deleteIfExists) deleteDir(dir); else throw new IOException("Cannot create directory that already exists: " + dir); } dir.mkdirs(); dir.deleteOnExit(); return dir; } public static File getSystemTempDirectory(File parentTempDir) throws IOException { if (parentTempDir != null && parentTempDir.exists() && parentTempDir.isDirectory()) return parentTempDir; final File t = File.createTempFile("java", ".tmp", parentTempDir); try { return t.getParentFile(); } finally { t.delete(); } } public static boolean deleteDir(File dir) { if (dir.isDirectory()) { String[] children = dir.list(); for (String child : children) { boolean success = deleteDir(new File(dir, child)); if (!success) { return false; } } } return dir.delete(); } public static File mkdirs(String packageName, File root) { String[] dirs = packageName.split("\\."); for (String dir : dirs) { File f = new File(root, dir); if (!f.exists()) { f.mkdir(); } root = f; } return root; } }