public static void backup ( final String filename ) throws IOException { final File dest = createFile ( filename ) ; if ( dest . exists ( ) ) { final File backupFile = generateBackupFilename ( filename ) ; LOGGER . debug ( "backing up file from " + filename + " to " + backupFile . getName ( ) ) ; if ( ! dest . renameTo ( backupFile ) ) { throw new IOException ( "Could not rename file from " + dest . getName ( ) + " to " + backupFile . getName ( ) ) ; } } }
Save the existing version of the file by renaming it to something ending with . &lt ; number&gt ; .