Java Utililty Methods Rename File

List of utility methods to do Rename File

Description

The list of methods to do Rename File are organized into topic(s).

Method

voidrename(String srcPath, String destPath)
rename
File file = new File(destPath);
file.delete();
file = new File(srcPath);
file.renameTo(new File(destPath));
booleanrename(String strFileName, String strRenameToName)
rename
File f = new File(strFileName);
if (f.exists()) {
    if (strRenameToName.indexOf('/') < 0) {
        strRenameToName = (f.getParent() + "/" + strRenameToName).replace("//", "/");
    return f.renameTo(new File(strRenameToName));
return false;
...
booleanrename(String was_name, String new_name)
rename
File was_file = new File(was_name);
File new_file = new File(new_name);
System.err.println(
        "[IOUtils] renaming: " + was_file.getAbsolutePath() + " to: " + new_file.getAbsolutePath());
return was_file.renameTo(new_file);
booleanrename_file_to_file(String n1, String n2)
renamfiltfile
try {
    File f1 = new File(n1);
    File f2 = new File(n2);
    return (f1 != null && f2 != null ? f1.renameTo(f2) : false);
} catch (SecurityException e) {
    return false;
voidrenameBackup(File backupFile)
rename a file to name.n where n is 1..2 ..3 ...
File parentDirectory = backupFile.getParentFile();
int index = 1;
while (true) {
    File newName = new File(parentDirectory, backupFile.getName() + "." + index++);
    if (newName.exists()) 
        continue; 
    if (!backupFile.renameTo(newName))
        throw new IllegalStateException("Cannot rename  temporary file " + backupFile.getAbsolutePath()
...
booleanrenameCanDelete()
rename Can Delete
if (rcdDone)
    return rcdValue;
File a = null;
File b = null;
try {
    a = File.createTempFile("java-rename-check-", "");
    b = File.createTempFile("java-rename-check-", "");
    rcdValue = a.renameTo(b);
...
voidrenameContigs(File aliasFile, File cytobandFile, File seqDir)
rename Contigs
BufferedReader aliasReader = null;
BufferedReader cytoReader = null;
PrintWriter cytoWriter = null;
File tmpCytoFile = new File(cytobandFile.getAbsolutePath() + ".tmp");
File backup = new File(cytobandFile.getAbsolutePath() + ".bak");
copyFile(cytobandFile, backup);
try {
    aliasReader = new BufferedReader(new FileReader(aliasFile));
...
booleanrenameDirectory(File directory, File newDirectory)
rename Directory
try {
    if (directory.isDirectory()) {
        directory.renameTo(newDirectory);
    } else {
        directory.mkdir();
        directory.renameTo(newDirectory);
    return true;
...
booleanrenameDirectory(File fromDir, File toDir)
rename Directory
if (fromDir.exists() && fromDir.isDirectory()) {
    if (fromDir.renameTo(toDir))
        return true;
    else
        return false;
} else
    return false;
booleanrenameDirectory(String in_currentDirectoryPath, String in_newDirectoryPath)
Renames a directory.
File currentDirectory = new File(in_currentDirectoryPath);
if (currentDirectory.exists() == false || currentDirectory.isDirectory() == false) {
    return false;
File newDirectory = new File(in_newDirectoryPath);
if (newDirectory.exists() == true) {
    return false;
if (currentDirectory.renameTo(newDirectory) == false) {
    return false;
return true;