Java File Rename renameFile(String oldPath, String newName)

Here you can find the source of renameFile(String oldPath, String newName)

Description

rename File

License

Apache License

Declaration

public static void renameFile(String oldPath, String newName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {

    public static void renameFile(String oldPath, String newName) {
        File file = new File(oldPath);
        if (!file.exists()) {
            return;
        }/*from www  .j av a  2  s  . co m*/
        String newPath = newName;

        if (file.getParent() != null) {
            newPath = file.getParent() + File.separator + newName;
        }
        file.renameTo(new File(newPath));
    }
}

Related

  1. renameFile(String oldFile, String newName)
  2. renameFile(String oldFileName, String newFileName)
  3. renameFile(String oldname, String newname)
  4. renameFile(String oldname, String newname)
  5. renameFile(String oldname, String newone)
  6. renameFile(String oldPath, String newPath)
  7. renameFile(String oldPath, String newPath, boolean overwrite)
  8. renameFile(String origPath, String destPath)
  9. renameFile(String path, String newPath)