Here you can find the source of renameToBackupName(File file)
public static void renameToBackupName(File file) throws IOException
//package com.java2s; //it under the terms of the GNU Affero General Public License as published by import java.io.File; import java.io.IOException; public class Main { public static void renameToBackupName(File file) throws IOException { File backupFile = new File(file.getParentFile(), file.getName() + "~"); if (backupFile.exists()) { boolean deleted = backupFile.delete(); if (!deleted) { throw new IOException("Cannot delete backup file " + backupFile); }// w w w . j av a 2 s . com } boolean renamed = file.renameTo(backupFile); if (!renamed) { throw new IOException("Cannot create backup file for " + file); } } public static void delete(File file, boolean recursive) throws IOException { if (file.exists()) { if (file.isDirectory() && recursive) { for (File childFile : file.listFiles()) { delete(childFile, recursive); } } if (!file.delete()) { throw new IOException("Cannot delete file " + file); } } } }