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

StringgetTempFileName()
Create temp file name based on current datetime
DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
return df.format(new Date());
FilegetTempFileName(String base, String ext)
Get a temporary file name, optionally prefixed by the base (if specified) and also optionally using the given extension (if specified, otherwise ".tmp" will be used).
if (base == null || base.length() <= 0)
    base = "";
if (ext == null || ext.length() <= 0)
    ext = "tmp";
UUID uuid = UUID.randomUUID();
String tmpName = sanitizeFileName(base + uuid.toString() + '.' + ext);
return new File(System.getProperty("java.io.tmpdir"), tmpName);
StringgetTempFileName(String fileExt)
get Temp File Name
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSSS");
return sdf.format(new Date()) + fileExt;
StringgetTempFilePath(String name)
get Temp File Path
String file = "";
String tmpfilepath = System.getProperty("java.io.tmpdir") + File.separator;
String tmpDiamondFilePath = "/dls/tmp/";
String username = System.getProperty("user.name");
File tmpDir = new File(tmpfilepath);
boolean canWrite = tmpDir.canWrite();
if (canWrite) {
    File folderTmp = new File(tmpfilepath + username);
...
StringgetTempFilePath(String signatureRequestId)
get Temp File Path
return (System.getProperty("java.io.tmpdir") + "/signature_" + signatureRequestId + ".jpg");
SetgetTempFiles()
get Temp Files
return new HashSet<File>(tempFiles);
ListgetTempFileWithFullPath()
get Temp File With Full Path
File file = File.createTempFile("OnlineReport", ".pdf");
List<String> fileDetails = new ArrayList<String>(2);
fileDetails.add(file.getParentFile().getAbsolutePath().replace("\\", "/"));
fileDetails.add(file.getName());
file.delete();
return fileDetails;
StringgetUniqueAFileName(String ext)
get Unique A File Name
return String.format("%s-%s.%s", (new SimpleDateFormat("ddMMyy-hhmmss_SSS")).format(new Date()),
        (new Random()).nextInt(3), ext);
FilegetUniqueFile(File dir, String prefix, String suffix)
Get an unique name under the specified directory
String name = prefix + "." + FILENAME_FORMAT.format(new Date()) + ".";
for (int i = 0; i < Integer.MAX_VALUE; i++) {
    File file = new File(dir, name + i + suffix);
    if (!file.exists()) {
        return file;
return null;
...
StringgetUniqueFileName()
get Unique File Name
return new SimpleDateFormat("yyyy_MM_dd__HH_mm_ss_SSS").format(new Date(System.currentTimeMillis()));