Java Rename File renameToBackupName(File file)

Here you can find the source of renameToBackupName(File file)

Description

rename To Backup Name

License

Open Source License

Declaration

public static boolean renameToBackupName(File file) 

Method Source Code

//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;
    }
}

Related

  1. renameTo(File fromFile, File toFile)
  2. renameTo(File orig, File dest)
  3. renameTo(File source, String newName)
  4. renameTo(final File srcFile, final File dstfile)
  5. renameTo(String fileName, String targetFileName)
  6. renameToBackupName(File file)
  7. renameToNextSequencedFile(String srcfile, String destfolder, String prefix, String suffix)
  8. renameToTempDir(File file, String newName)
  9. renameToTemporaryName(final File flFileToRename, final String strPrefix)