Java Rename File rename(File aFile, File dest)

Here you can find the source of rename(File aFile, File dest)

Description

Renames the file aFile.

License

Open Source License

Parameter

Parameter Description
aFile The file to be renamed.
dest The new abstract pathname for the named file

Exception

Parameter Description
IOException if the the renaming was not successful.

Declaration

public static void rename(File aFile, File dest) throws IOException 

Method Source Code


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

import java.io.IOException;

public class Main {
    /**/* www .ja  v  a 2  s . c om*/
     * Renames the file <code>aFile</code>.
     *
     * @param  aFile The file to be renamed.
     * @param  dest  The new abstract pathname for the named file
     * @throws IOException if the the renaming was not successful.
     */
    public static void rename(File aFile, File dest) throws IOException {
        if (!aFile.renameTo(dest)) {
            throw new IOException("Failed to rename " + aFile + " to " + dest);
        }
    }
}

Related

  1. rename(File f1, File f2)
  2. rename(File file, String newName, boolean overwite)
  3. rename(File file, String prefix, String name, HashMap optional)
  4. rename(File from)