public static File generateSafetyUniqueFile(File file) throws IOException {
        String path = file.getCanonicalPath();
        String ext = getExtension(path);
        char separator = '_';

        String name1 = Long.toString(System.currentTimeMillis());

        Random rnd = new Random();
        String name2 = Integer.toString(rnd.nextInt(9999));

        String fullName;
        if (ext != null && !ext.isEmpty()) {
            fullName = name1 + separator + name2 + separator + ext;
        } else {
            fullName = name1 + separator + name2;
        }

        File file2 = new File(getFullPath(path), fullName);

        return getUniqueFile(file2, separator);
    }
public static File generateSafetyUniqueFile ( File file ) throws IOException { String path = file . getCanonicalPath ( ) ; String ext = getExtension ( path ) ; char separator = '_' ; String name1 = Long . toString ( System . currentTimeMillis ( ) ) ; Random rnd = new Random ( ) ; String name2 = Integer . toString ( rnd . nextInt ( 9999 ) ) ; String fullName ; if ( ext != null && ! ext . isEmpty ( ) ) { fullName = name1 + separator + name2 + separator + ext ; } else { fullName = name1 + separator + name2 ; } File file2 = new File ( getFullPath ( path ) , fullName ) ; return getUniqueFile ( file2 , separator ) ; }
Creates and returns a safe file name on the system without duplication in the specified directory.
If a duplicate file name exists, it is returned by appending a number after the file name.
File extensions are separated by '_' character.
<pre>
ex) 1111111111_txt
</pre>

@param file the file to seek
@return an unique file
@throws IOException if failed to obtain an unique file