Java Utililty Methods Temp File Create

List of utility methods to do Temp File Create

Description

The list of methods to do Temp File Create are organized into topic(s).

Method

FilegetTempFile(String config)
get Temp File
return getTempFile(config, ".xml");
FilegetTempFile(String extension)
get Temp File
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
String uuid = UUID.randomUUID().toString();
return new File(tmpDir, uuid + "." + extension);
FilegetTempFile(String fileId)
get Temp File
return new File(getTempDirectory(), fileId);
FilegetTempFile(String filePrefix, boolean deleteOnExit)
get Temp File
String tempFileName = filePrefix + "-" + System.nanoTime();
File tempFile = null;
try {
    tempFile = File.createTempFile(tempFileName, ".txt");
    if (deleteOnExit) {
        tempFile.deleteOnExit();
} catch (IOException e) {
...
FilegetTempFile(String name)
get Temp File
return new File(TEMP_PATH_ROOT, name);
FilegetTempFile(String tmpdir)
get Temp File
String name = String.valueOf(System.currentTimeMillis() + ++counter);
return new File(tmpdir, name);
FilegetTempFileDir()
Returns the Ofbiz temporary file directory (for uploaded files, etc).
return new File(new File(System.getProperty("ofbiz.home"), "runtime"), "tmp");
FilegetTempFileFor(File file)
Find a non-existing file in the same directory using the same name as prefix.
File parent = file.getParentFile();
String name = file.getName();
File result;
int index = 0;
do {
    result = new File(parent, name + "_" + index++);
} while (result.exists());
return result;
...
StringgetTempFileGivenName(File file)
Method getTempFileGivenName
String fileName = file.getName();
int index = fileName.indexOf(GIVEN_NAME_SUFFIX);
if (index < 0) {
    return fileName;
} else {
    return fileName.substring(0, index);
StringgetTempFileName()
get Temp File Name
String tmpDir = System.getProperty("java.io.tmpdir");
if (tmpDir == null) {
    tmpDir = "/tmp";
String uuid = UUID.randomUUID().toString();
File f = new File(tmpDir, uuid);
return f.getAbsolutePath();