Java Temp File Create getUniqueFilename(String filename, String extension)

Here you can find the source of getUniqueFilename(String filename, String extension)

Description

get Unique Filename

License

Open Source License

Declaration

public static String getUniqueFilename(String filename, String extension) 

Method Source Code

//package com.java2s;
/**//from   w  w w.ja v  a2  s .  co  m
 * (c) 2014 Cisco and/or its affiliates. All rights reserved.
 * 
 * This software is released under the Eclipse Public License. The details can be found in the file LICENSE. 
 * Any dependent libraries supplied by third parties are provided under their own open source licenses as 
 * described in their own LICENSE files, generally named .LICENSE.txt. The libraries supplied by Cisco as 
 * part of the Composite Information Server/Cisco Data Virtualization Server, particularly csadmin-XXXX.jar, 
 * csarchive-XXXX.jar, csbase-XXXX.jar, csclient-XXXX.jar, cscommon-XXXX.jar, csext-XXXX.jar, csjdbc-XXXX.jar, 
 * csserverutil-XXXX.jar, csserver-XXXX.jar, cswebapi-XXXX.jar, and customproc-XXXX.jar (where -XXXX is an 
 * optional version number) are provided as a convenience, but are covered under the licensing for the 
 * Composite Information Server/Cisco Data Virtualization Server. They cannot be used in any way except 
 * through a valid license for that product.
 * 
 * This software is released AS-IS!. Support for this software is not covered by standard maintenance agreements with Cisco. 
 * Any support for this software by Cisco would be covered by paid consulting agreements, and would be billable work.
 * 
 */

import java.text.Format;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static String getUniqueFilename(String filename, String extension) {
        return filename + "_" + getCurrentDateAsString("yyyy_MM_dd_HH_mm_ss_SSS") + "." + extension;
    }

    /**
     * Get the current date timestamp as a string
     * 
     * @param timestampFormat - timestamp format.  e.g. yyyy-MM-dd HH:mm:ss.SSS
     * @return
     */
    public static String getCurrentDateAsString(String timestampFormat) {
        Format formatter;
        Date date = new Date();
        formatter = new SimpleDateFormat(timestampFormat);
        return formatter.format(date).toString();
    }
}

Related

  1. getTempFiles()
  2. getTempFileWithFullPath()
  3. getUniqueAFileName(String ext)
  4. getUniqueFile(File dir, String prefix, String suffix)
  5. getUniqueFileName()
  6. getUniqueFileName(String fileNamePrefix, String fileExtension)
  7. getUniqueFileName(String originalFileName)
  8. getUniqueTempFile(final boolean autoDelete, final File parentFolder, final String suffix)
  9. newTmpFile(String content)