Here you can find the source of renameFile(String oldname, String newname)
public static boolean renameFile(String oldname, String newname)
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static boolean renameFile(String oldname, String newname) { // File (or directory) with old name File file = new File(oldname); // File (or directory) with new name File file2 = new File(newname); if (file2.exists()) { System.out/*from ww w . j av a 2 s .co m*/ .println("can not rename since target name is same as source name"); return false; } // Rename file (or directory) boolean success = file.renameTo(file2); if (!success) { System.out.println("can not rename"); } return true; } public static boolean renameFile(File oldFile, File newFile) { if (newFile.exists()) { System.out .println("can not rename since target name is same as source name"); return false; } boolean success = oldFile.renameTo(newFile); if (!success) { System.out.println("can not rename"); } return true; } }