Here you can find the source of rename(File oldFile, File newFile)
public static void rename(File oldFile, File newFile) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; public class Main { public static void rename(File oldFile, File newFile) throws IOException { rename(oldFile, newFile, false); }//from ww w.j a v a 2s .c o m public static void rename(File oldFile, File newFile, boolean ignoreExisting) throws IOException { if (newFile.exists()) { if (ignoreExisting) return; throw new IOException("A file with the name " + newFile.getName() + " already exists"); } boolean success = oldFile.renameTo(newFile); if (!success) throw new IOException("Could note rename file: " + oldFile.getName() + " to " + newFile.getName() + " in path " + oldFile.getParent()); } }