Java Temp Directory Get getTempDir(String name, String prefix, File parentDir)

Here you can find the source of getTempDir(String name, String prefix, File parentDir)

Description

Returns An abstract pathname denoting an empty directory (this directory is not created).

License

LGPL

Parameter

Parameter Description
name The name of the directory to create. If null, generate a name.
prefix The prefix string to be used in generating the file's name
parentDir The parent directory in which the directory is to be created, or null if the default temporary-file directory is to be used

Return

An abstract pathname denoting an empty directory

Declaration

public static File getTempDir(String name, String prefix, File parentDir) 

Method Source Code


//package com.java2s;
/*//from  www .  ja va2s .  c  o  m
 GNU LESSER GENERAL PUBLIC LICENSE
 Version 3, 29 June 2007
    
 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.
    
    
 This version of the GNU Lesser General Public License incorporates
 the terms and conditions of version 3 of the GNU General Public
 License
 */

import java.io.File;

import java.io.IOException;

public class Main {
    /**
     * Returns An abstract pathname denoting an empty directory (this directory is
     * not created).
     * 
     * @param name
     *          The name of the directory to create. If null, generate a name.
     * @param prefix
     *          The prefix string to be used in generating the file's name
     * @param parentDir
     *          The parent directory in which the directory is to be created, or
     *          null if the default temporary-file directory is to be used
     * @return An abstract pathname denoting an empty directory
     */
    public static File getTempDir(String name, String prefix, File parentDir) {
        prefix = prefix == null ? "ejpt" : prefix;
        parentDir = parentDir != null ? parentDir : new File(System.getProperty("java.io.tmpdir"));

        if (name == null) {
            try {
                File temp = File.createTempFile(prefix, "");
                name = temp.getName();
                temp.delete();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }

        return new File(parentDir, name);
    }
}

Related

  1. getTempDir()
  2. getTempDir(File baseDir)
  3. getTempDir(final String directory, final String prefix, boolean autodelete)
  4. getTempDir(Object fileID, String fileName)
  5. getTempDir(String desc)
  6. getTempDir(String path)
  7. getTempDir(String prefix)
  8. getTempDir(String suffix)
  9. getTempDirectory()