public static File getTempFileFor ( File file ) { File parent = file . getParentFile ( ) ; String name = file . getName ( ) ; File result ; int index = 0 ; do { result = new File ( parent , name + "_" + index ++ ) ; } while ( result . exists ( ) ) ; return result ; }
Find a non - existing file in the same directory using the same name as prefix .