Java File Rename renameFile(final String oldName, final String newName)

Here you can find the source of renameFile(final String oldName, final String newName)

Description

rename a file

License

Open Source License

Parameter

Parameter Description
oldName a parameter
newName a parameter

Return

true if succeeded

Declaration

public final static boolean renameFile(final String oldName, final String newName) 

Method Source Code

//package com.java2s;
/*//from w ww . j a v a2 s .  c o m
 * Copyright (c) 2006 Stephan D. Cote' - All rights reserved.
 * 
 * This program and the accompanying materials are made available under the 
 * terms of the MIT License which accompanies this distribution, and is 
 * available at http://creativecommons.org/licenses/MIT/
 *
 * Contributors:
 *   Stephan D. Cote 
 *      - Initial API and implementation
 */

import java.io.File;

public class Main {
    /**
     * rename a file
     *
     * @param oldName
     * @param newName
     *
     * @return true if succeeded
     */
    public final static boolean renameFile(final String oldName, final String newName) {
        final File f_old = new File(oldName);
        final File f_new = new File(newName);
        final boolean ret = f_old.renameTo(f_new);
        return ret;
    }
}

Related

  1. renameFile(File src, File dest, boolean overwrite)
  2. renameFile(File srcFile, File destFile)
  3. renameFile(File srcFile, File dstFile)
  4. renameFile(File srcFile, File renameToFile)
  5. renameFile(final File path, final String fname)
  6. renameFile(String currentPath, String newPath)
  7. renameFile(String file, String toFile)
  8. renameFile(String fileFrom, String fileTo)
  9. renameFile(String fileName, String destFilename)