Here you can find the source of renameToBackupName(File file)
public static boolean renameToBackupName(File file)
//package com.java2s; import java.io.*; public class Main { public static boolean renameToBackupName(File file) { return file.renameTo(backupFile(file)); }//from www .ja va 2 s . c o m public static File backupFile(File file) { int max = 1000; String filename = file.toString(); File backup = new File(filename + "~"); if (!backup.exists()) { return backup; } for (int i = 1; i <= max; i++) { backup = new File(filename + ".~" + i + ".~"); if (!backup.exists()) { return backup; } } return null; } }