Java File Rename renameFile(String origPath, String destPath)

Here you can find the source of renameFile(String origPath, String destPath)

Description

Rename a file.

License

Open Source License

Return

true if successfully renamed

Declaration

public static boolean renameFile(String origPath, String destPath) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 Firestar Software, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from   w  ww.ja v  a  2 s .  c  om*/
 *     Firestar Software, Inc. - initial API and implementation
 *
 * Author:
 *     Gabriel Oancea
 *
 *******************************************************************************/

import java.io.*;

public class Main {
    /**
     * Rename a file. Just like File.renameTo(), but logs failure.
     * 
     * @return <code>true</code> if successfully renamed
     */
    public static boolean renameFile(String origPath, String destPath) {
        File orig = new File(origPath);
        File dest = new File(destPath);
        if (!orig.exists() || dest.exists())
            return false;
        return orig.renameTo(dest);
    }
}

Related

  1. renameFile(String oldname, String newname)
  2. renameFile(String oldname, String newone)
  3. renameFile(String oldPath, String newName)
  4. renameFile(String oldPath, String newPath)
  5. renameFile(String oldPath, String newPath, boolean overwrite)
  6. renameFile(String path, String newPath)