Java Rename File rename(File source, File target)

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

Description

rename

License

LGPL

Declaration

public static boolean rename(File source, File target) 

Method Source Code

//package com.java2s;
/*//www.  ja va2s.c o  m
 *   This software is distributed under the terms of the FSF 
 *   Gnu Lesser General Public License (see lgpl.txt). 
 *
 *   This program is distributed WITHOUT ANY WARRANTY. See the
 *   GNU General Public License for more details.
 */

import java.io.File;

public class Main {
    public static boolean rename(File source, File target) {
        if (source == null || target == null) {
            throw new IllegalArgumentException("Input cannot be null.");
        }
        return source.renameTo(target);
    }

    public static boolean rename(String parentPathAbsolute, String oldName,
            String newName) {
        boolean status = false;

        File oldFile = new File(parentPathAbsolute + File.separatorChar
                + oldName);
        status = oldFile.renameTo(new File(parentPathAbsolute
                + File.separatorChar + newName));

        return status;
    }
}

Related

  1. rename(File from, File to, boolean overwrite)
  2. rename(File oldFile, File newFile)
  3. rename(File pFrom, File pTo)
  4. rename(File pFrom, File pTo, boolean pOverWrite)
  5. rename(File source, File dest)
  6. rename(File src, File dest)
  7. rename(File src, String name)
  8. rename(File srcFile, String newName)
  9. rename(final String src, final String dst)