Java Temp Directory Create createTempDirectory(String prefix)

Here you can find the source of createTempDirectory(String prefix)

Description

Creates a temporary directory whose name starts with the given prefix .

License

Open Source License

Parameter

Parameter Description
prefix the prefix of the directory name.

Exception

Parameter Description
IOException an exception

Return

the directory created as a instance.

Declaration

static File createTempDirectory(String prefix) throws IOException 

Method Source Code

//package com.java2s;
/**/* w w  w  . j  a v a  2s. co  m*/
 * Copyright 2016 LinkedIn Corp. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 */

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

public class Main {
    /**
     * Creates a temporary directory whose name starts with the given {@code prefix}.
     * @param prefix the prefix of the directory name.
     * @return the directory created as a {@link File} instance.
     * @throws IOException
     */
    static File createTempDirectory(String prefix) throws IOException {
        File tempDir = Files.createTempDirectory(prefix).toFile();
        tempDir.deleteOnExit();
        return tempDir;
    }
}

Related

  1. createTempDirectory()
  2. createTempDirectory()
  3. createTempDirectory()
  4. createTempDirectory(File parent, String prefix)
  5. createTempDirectory(String prefix)
  6. makeTempDir()
  7. makeTempDir(String name)
  8. makeTempDir(String prefix)
  9. makeTempDir(String prefix)