public class TempFileManager extends Object
File.createTempFile(java.lang.String, java.lang.String)
, this class provides a static method to
create temporary files. The temporary files will be created in a special directory to be cleaned
up the next time this class is loaded by the JVM. This functionality is required because Win32
platforms will not allow the JVM to delete files that are open. This causes problems with items
such as JARs that get opened by a URLClassLoader and can therefore not be deleted by the JVM
(including deleteOnExit).
The caller should not need to create an instance of this class, although it is possible. Simply
use the static methods to perform the required operations. Note that all files created by this
class should be considered as deleted at JVM exit (although the actual deletion may be delayed).
If persistent temporary files are required, use File
instead.
Refer to Sun bugs 4171239 and 4950148 for more details.
Thanks to Mike Pilone for this code, which was sourced from
http://www.devx.com/Java/Article/22018/ and contributed to Apache.Constructor and Description |
---|
TempFileManager() |
Modifier and Type | Method and Description |
---|---|
static File |
createTempFile(String prefix,
String suffix)
Creates a temporary file in the proper directory to allow for cleanup after execution.
|
static void |
main(String[] args)
Utility method to load the TempFileManager at any time and allow it to clean the temporary
files that may be left from previous instances
|
public static File createTempFile(String prefix, String suffix) throws IOException
File.createTempFile(java.lang.String, java.lang.String,
java.io.File)
so refer to it for more documentation. Any file created using this method should
be considered as deleted at JVM exit; therefore, do not use this method to create files that
need to be persistent between application runs.prefix
- the prefix string used in generating the file name; must be at least three
characters longsuffix
- the suffix string to be used in generating the file's name; may be null, in which
case the suffix ".tmp" will be usedIOException
- if a file could not be createdpublic static void main(String[] args)
args
- command line arguments are currently not supportedCopyright © 2004–2014 The Apache Software Foundation. All rights reserved.