Java File Rename renameFile(String oldname, String newone)

Here you can find the source of renameFile(String oldname, String newone)

Description

Renames a file from oldname to newone.

License

Open Source License

Parameter

Parameter Description
oldname The name of the file to be renamed.
newone The new file name.

Return

True if everything went fine and false otherwise.

Declaration

public static boolean renameFile(String oldname, String newone) 

Method Source Code


//package com.java2s;
import java.io.File;

public class Main {
    /**//  w  w w.j  av a  2  s.com
     * Renames a file from oldname to newone.
     * 
     * @param oldname The name of the file to be renamed.
     * @param newone The new file name.
     * @return <i>True</ib> if everything went fine and <i>false</i> otherwise.
     */
    public static boolean renameFile(String oldname, String newone) {
        boolean result = false;
        File file = new File(oldname);
        if (file.exists()) {
            result = file.renameTo(new File(newone));
        }
        return result;
    }
}

Related

  1. renameFile(String newName, String oldName)
  2. renameFile(String oldFile, String newName)
  3. renameFile(String oldFileName, String newFileName)
  4. renameFile(String oldname, String newname)
  5. renameFile(String oldname, String newname)
  6. renameFile(String oldPath, String newName)
  7. renameFile(String oldPath, String newPath)
  8. renameFile(String oldPath, String newPath, boolean overwrite)
  9. renameFile(String origPath, String destPath)