public final class TempFileManager extends Object
File.createTempFile(String, String)
API creates rather meaningless file names and
only in the system's temp directory.File.createTempFile(String, String)
and File.deleteOnExit()
, and can be used as a drop-in replacement.Modifier and Type | Method and Description |
---|---|
File |
createTempFile(String prefix) |
File |
createTempFile(String prefix,
String suffix)
Creates a new, uniquely-named temporary file in this object's
tempDir
with user-defined prefix and suffix (both may be null or empty and won't be trimmed). |
void |
deleteAll() |
static String |
getJavaIoTmpDir()
Returns the value of system property
java.io.tmpdir , the system's temp directory. |
File |
getTempDir()
Returns the temporary directory or sub-directory under which temporary files are created.
|
static TempFileManager |
instance() |
static TempFileManager |
instance(File tempDir) |
static TempFileManager |
instance(String subDirName)
Creates an instance using a subdirectory of the system's temporary directory.
|
boolean |
isDeleteOnExit() |
void |
setDeleteOnExit(boolean deleteOnExit)
Instructs this file manager to delete its temporary files during JVM shutdown.
This status can be turned on and off unlike File.deleteOnExit() . |
String |
toString() |
public static TempFileManager instance()
public static TempFileManager instance(String subDirName)
subDirName
- name of subdirectorypublic static TempFileManager instance(File tempDir)
public void deleteAll()
public File getTempDir()
public File createTempFile(String prefix, String suffix)
tempDir
with user-defined prefix and suffix (both may be null or empty and won't be trimmed).
This method behaves similarly to File.createTempFile(String, String)
and
may be used as a drop-in replacement.
This method is synchronized
to help ensure uniqueness of temporary files.
prefix
- optional file name prefixsuffix
- optional file name suffixpublic boolean isDeleteOnExit()
public void setDeleteOnExit(boolean deleteOnExit)
File.deleteOnExit()
.deleteOnExit
- delete the file in a shutdown hook on JVM exitpublic static String getJavaIoTmpDir()
java.io.tmpdir
, the system's temp directory.Copyright © 2004–2024 The Apache Software Foundation. All rights reserved.