Java Rename File renameTo(File currentFile, String newName)

Here you can find the source of renameTo(File currentFile, String newName)

Description

Platform independent rename function

License

Open Source License

Parameter

Parameter Description
currentFile file to rename
newName rename to this (same directory)

Declaration

public static void renameTo(File currentFile, String newName) 

Method Source Code


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

import java.io.*;

import com.google.common.io.Files;

public class Main {
    /**//from w  w w.  ja  v a  2 s.  c om
     * Platform independent rename function
     *
     * @param currentFile file to rename
     * @param newName     rename to this (same directory)
     */
    public static void renameTo(File currentFile, String newName) {
        try {
            File newFile = new File(newName);
            Files.move(currentFile, newFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. renameLocal(String oldPath, String newPath)
  2. renameOldFile(final String fileName)
  3. renameOverwrite(String oldname, String newname)
  4. renameSuffix(File f, String suffix)
  5. renameTempDMLScript(String dmlScriptFile)
  6. renameTo(File from, File to, boolean deleteDestination)
  7. renameTo(File fromFile, File toFile)
  8. renameTo(File orig, File dest)
  9. renameTo(File source, String newName)