Java Rename File rename(String srcFilename, String destFilename)

Here you can find the source of rename(String srcFilename, String destFilename)

Description

renames a file to the new filename

License

Open Source License

Parameter

Parameter Description
srcFilename old filename
destFilename new filename

Return

true if success, otherwise false

Declaration

public static boolean rename(String srcFilename, String destFilename) 

Method Source Code


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

import java.io.*;

public class Main {
    /**//  ww w  .  ja  v a2s.c om
     * renames a file to the new filename
     * 
     * @param srcFilename
     *            old filename
     * @param destFilename
     *            new filename
     * @return true if success, otherwise false
     */
    public static boolean rename(String srcFilename, String destFilename) {
        File srcFile;
        File destFile;
        boolean result = false;

        srcFile = new File(srcFilename);
        destFile = new File(destFilename);
        try {
            result = srcFile.renameTo(destFile);
        } catch (Exception e) {
            System.err.println("failed to rename file: " + e.toString());
            // e.printStackTrace();
        } finally {
            srcFile = null;
            destFile = null;
        }
        return result;
    }
}

Related

  1. rename(String oldFile, String newFile)
  2. rename(String oldName, String newName)
  3. reName(String oldName, String newName)
  4. rename(String platformLibPath, String newPath)
  5. reName(String s, String s1)
  6. rename(String srcPath, String destPath)
  7. rename(String strFileName, String strRenameToName)
  8. rename(String was_name, String new_name)
  9. rename_file_to_file(String n1, String n2)