Here you can find the source of renameTo(File orig, File dest)
public static boolean renameTo(File orig, File dest)
//package com.java2s; /* This code is part of Freenet. It is distributed under the GNU General * Public License, version 2 (or at your option any later version). See * http://www.gnu.org/ for further details of the GPL. */ import java.io.File; import java.util.logging.Level; import java.util.logging.Logger; public class Main { private static Logger logger = Logger.getLogger("net.sf.thingamablog.util.io"); public static boolean renameTo(File orig, File dest) { // Try an atomic rename // Shall we prevent symlink-race-conditions here ? if (orig.equals(dest)) throw new IllegalArgumentException("Huh? the two file descriptors are the same!"); if (!orig.exists()) { throw new IllegalArgumentException("Original doesn't exist!"); }/*from w w w .j a va 2s .c o m*/ if (!orig.renameTo(dest)) { // Not supported on some systems (Windows) if (!dest.delete()) { if (dest.exists()) { logger.log(Level.SEVERE, "Could not delete " + dest + " - check permissions"); } } if (!orig.renameTo(dest)) { logger.log(Level.SEVERE, "Could not rename " + orig + " to " + dest + (dest.exists() ? " (target exists)" : "") + (orig.exists() ? " (source exists)" : "") + " - check permissions"); return false; } } return true; } }