Java Temp Directory Create createTempDir()

Here you can find the source of createTempDir()

Description

Create a temporary directory.

License

Open Source License

Declaration

public static File createTempDir() throws IllegalStateException 

Method Source Code

//package com.java2s;
/*/*from   w ww  .  j  a  va 2 s.c  o m*/
 * Copyright 2012 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

public class Main {
    /**
     * Create a temporary directory.
     */
    public static File createTempDir() throws IllegalStateException {
        File baseDir = getTempDirectory();
        try {
            return Files.createTempDirectory(baseDir.toPath(), "tmpdir")
                    .toFile();
        } catch (IOException e) {
            throw new IllegalStateException(
                    "Error while creating temporary directory", e);
        }
    }

    /**
     * Get the current system temp directory.
     */
    public static File getTempDirectory() {
        return new File(System.getProperty("java.io.tmpdir"));
    }
}

Related

  1. createTempDir()
  2. createTempDir(final String prefix)
  3. createTempDir(String prefix)
  4. createTempDir(String subdirectory)