Java Utililty Methods Temp Directory Create

List of utility methods to do Temp Directory Create

Description

The list of methods to do Temp Directory Create are organized into topic(s).

Method

FilecreateTempDirectory(String prefix)
Create a uniquely-named temporary directory.
File baseDir = new File(System.getProperty("java.io.tmpdir"));
baseDir.mkdirs();
while (true) {
    File tempDir = new File(baseDir, prefix + Math.abs(random.nextLong()));
    if (!tempDir.exists()) {
        if (tempDir.mkdir()) {
            return tempDir;
FilecreateTempDirectory(String prefix)
Creates a temporary directory whose name starts with the given prefix .
File tempDir = Files.createTempDirectory(prefix).toFile();
tempDir.deleteOnExit();
return tempDir;
FilemakeTempDir()
make Temp Dir
File tmpFile = File.createTempFile("temp-dir", "tmp");
tmpFile.deleteOnExit();
String filename = tmpFile.getCanonicalPath();
String dirname = filename.substring(0, filename.length() - 4);
File tmpDir = new File(dirname);
if (!tmpDir.mkdir()) {
    throw new IOException("Can't create temp directory: " + dirname);
return tmpDir;
FilemakeTempDir(String name)
make Temp Dir
File tempDir = new File(tmpDirName);
if (!tempDir.isDirectory()) {
    throw new RuntimeException("Temp dir " + tmpDirName + " does not exist");
File subDir = new File(tempDir, name);
if (!subDir.exists()) {
    subDir.mkdir();
return subDir;
FilemakeTempDir(String prefix)
make Temp Dir
File temp;
do {
    temp = new File(System.getProperty("java.io.tmpdir"), prefix + '-' + UUID.randomUUID());
} while (temp.exists());
if (!temp.mkdir()) {
    throw new IOException("Couldn't create temp directory: " + temp);
cTempFiles.add(temp);
...
FilemakeTempDir(String prefix)
make Temp Dir
if (null == prefix) {
    prefix = "tempDir";
File tempFile = null;
for (int i = 0; i < 10; i++) {
    try {
        tempFile = File.createTempFile(prefix, "tmp");
        tempFile.delete();
...
FilemakeTempDir(String prefix, String suffix)
make Temp Dir
final File instrDir = File.createTempFile(prefix, suffix);
instrDir.delete();
instrDir.mkdir();
return instrDir;
FilemakeTempDirectory(String dirName, boolean deleteIfExists)
make Temp Directory
return makeTempDirectory(null, dirName, deleteIfExists);
FilemakeTempDirectory(String prefix, String suffix)
Creates an empty directory in the default temporary-file directory, using the given prefix and suffix to generate its name.
File dir = File.createTempFile(prefix, suffix);
if (!dir.delete())
    throw new IOException("could not delete temporary file: " + dir);
if (!dir.mkdir())
    throw new IOException("could not make temporary directory: " + dir);
return dir;
FilemakeTemporaryDirectory()
make Temporary Directory
return makeTemporaryDirectory("kiradb", ".index");