Here you can find the source of getTempDir(String name, String prefix, File parentDir)
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 |
public static File getTempDir(String name, String prefix, File parentDir)
//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); } }