public static File createTempDirectory(String _path, String _prefix, int _length, boolean _timestamp, boolean _deleteOnExit) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd_HHmmss-SSS");
        String randomStr = StringUtil.randomString(_length);

        StringBuilder fileName = new StringBuilder();

        if (_prefix != null) {
            fileName.append(_prefix);
        }
        fileName.append(randomStr);

        if (_timestamp) {
            fileName.append("_").append(formatter.format(new Date()));
        }
        File result = createTempDirectory(_path, fileName.toString(), _deleteOnExit);
        while (result == null) {
            result = createTempDirectory(_path, _prefix, _length, _timestamp, _deleteOnExit);
        }
        return result;
    }
public static File createTempDirectory ( String _path , String _prefix , int _length , boolean _timestamp , boolean _deleteOnExit ) { SimpleDateFormat formatter = new SimpleDateFormat ( "yyyyMMdd_HHmmss-SSS" ) ; String randomStr = StringUtil . randomString ( _length ) ; StringBuilder fileName = new StringBuilder ( ) ; if ( _prefix != null ) { fileName . append ( _prefix ) ; } fileName . append ( randomStr ) ; if ( _timestamp ) { fileName . append ( "_" ) . append ( formatter . format ( new Date ( ) ) ) ; } File result = createTempDirectory ( _path , fileName . toString ( ) , _deleteOnExit ) ; while ( result == null ) { result = createTempDirectory ( _path , _prefix , _length , _timestamp , _deleteOnExit ) ; } return result ; }
Creates a temporary directory in the given path.
You can  specify certain files to get a random unique name.
@param _path where to place the temp folder
@param _prefix prefix of the folder
@param _length length of random chars
@param _timestamp add timestamp (yyyyMMdd_HHmmss-SSS) to directory name
@param _deleteOnExit mark directory for deletion on jvm termination
@return file