Here you can find the source of renameFile(File file, String name)
public static File renameFile(File file, String name)
//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; } }