Java File Rename renameFile(File file, String newFilename)

Here you can find the source of renameFile(File file, String newFilename)

Description

rename File

License

Open Source License

Parameter

Parameter Description
file a parameter
newFilename a parameter

Return

if the operation is success return true else return false

Declaration

public static boolean renameFile(File file, String newFilename) 

Method Source Code


//package com.java2s;

import java.io.File;

public class Main {
    /**//from www .  j  ava 2s .  c  om
     * 
     * @author Marquis
     * @Create Date: 2008-3-29
     * @param file
     * @param newFilename
     * @return if the operation is success return true else return false
     */
    public static boolean renameFile(File file, String newFilename) {
        if (file.exists() == false)
            return false;

        String path = file.getPath();
        File new_file = new File(path + File.separator + newFilename);

        return file.renameTo(new_file);
    }
}

Related

  1. renameFile(File file, String ext)
  2. renameFile(File file, String name)
  3. renameFile(File file, String newName)
  4. renameFile(File file, String newName)
  5. renameFile(File file, String newName)
  6. renameFile(File file, String newName)