Java File Rename renameFile(File file, String name)

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

Description

rename File

License

Open Source License

Declaration

public static File renameFile(File file, String name) 

Method Source Code


//package com.java2s;

import java.io.File;

public class Main {

    public static File renameFile(File file, String name) {
        String filePath = file.getAbsolutePath();
        String fileName = file.getName();
        String newFilePath = filePath.substring(0, filePath.length() - fileName.length()) + name;
        File newFile = new File(newFilePath);
        file.renameTo(newFile);//from w  w w. j a  va 2s.c  om
        return newFile;
    }
}

Related

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