Java Rename File rename(File src, String name)

Here you can find the source of rename(File src, String name)

Description

Renames a file using a string.

License

Open Source License

Parameter

Parameter Description
src The file to rename.
name The new name of the file.

Return

the new file or null if it failed.

Declaration

public static File rename(File src, String name) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    /**/*w  w  w .  ja va2  s .c  o  m*/
     * Renames a file using a string.
     * 
     * @param src The file to rename.
     * @param name The new name of the file.
     * @return the new file or null if it failed.
     */
    public static File rename(File src, String name) {
        File ret = new File(src.getParentFile(), name);

        if (src.renameTo(ret))
            return ret;
        else
            return null;
    }
}

Related

  1. rename(File pFrom, File pTo)
  2. rename(File pFrom, File pTo, boolean pOverWrite)
  3. rename(File source, File dest)
  4. rename(File source, File target)
  5. rename(File src, File dest)
  6. rename(File srcFile, String newName)
  7. rename(final String src, final String dst)
  8. rename(String existingFile, String newFilename)
  9. rename(String fileName, String distFile)