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 .