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

FilecreateTempDir()
Create a temporary directory.
File baseDir = getTempDirectory();
try {
    return Files.createTempDirectory(baseDir.toPath(), "tmpdir").toFile();
} catch (IOException e) {
    throw new IllegalStateException("Error while creating temporary directory", e);
FilecreateTempDir()
Guava's method, moved here to avoid a huge dependency TODO: maybe switch to JDK 7 to use its java.nio.file.Files#createTempDirectory()
return getTempDir(System.currentTimeMillis() + "");
PathcreateTempDir(final String prefix)
create Temp Dir
try {
    return Files.createTempDirectory(prefix);
} catch (IOException ex) {
    ex.printStackTrace();
return null;
FilecreateTempDir(String prefix)
create Temp Dir
return createTempDir(new File(System.getProperty("java.io.tmpdir")), prefix);
PathcreateTempDir(String subdirectory)
create Temp Dir
String systemTmpDir = System.getProperty("java.io.tmpdir");
Path tempDirPath = Paths.get(systemTmpDir, subdirectory);
if (Files.notExists(tempDirPath)) {
    return Files.createDirectory(tempDirPath);
} else {
    return tempDirPath;
FilecreateTempDir(String suffix)
create Temp Dir
mkdirs(TMP);
File tmpFile = File.createTempFile("tmpdir-", suffix, TMP);
deleteFile(tmpFile);
mkdirs(tmpFile);
return tmpFile;
PathcreateTempDirectory()
Creates a new temp directory in the java temp folder.
final File parent = new File(getTempDirValue());
if (!parent.exists() || !parent.canWrite()) {
    throw new RuntimeException("Cannot access temporary directory under: " + getTempDirValue());
File child;
try {
    child = Files.createTempDirectory(parent.toPath(), null).toFile();
} catch (IOException e) {
...
FilecreateTempDirectory()
create Temp Directory
try {
    final File directory = Files.createTempDirectory("sqs").toFile();
    directory.deleteOnExit(); 
    return directory;
} catch (IOException e) {
    throw Throwables.propagate(e);
FilecreateTempDirectory()
create Temp Directory
final File temp;
temp = Files.createTempDirectory("advtmp").toFile();
return temp;
FilecreateTempDirectory(File parent, String prefix)
Create temporary directory and use specified parent.
if (parent == null) {
    parent = new File(System.getProperty("java.io.tmpdir"));
return Files.createTempDirectory(parent.toPath(), prefix).toFile();