Here you can find the source of rename(File from, File to, boolean overwrite)
public static synchronized void rename(File from, File to, boolean overwrite) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static synchronized void rename(File from, File to, boolean overwrite) throws IOException { boolean success = true; if (!from.exists()) { throw new IOException("file from=[" + from.getAbsolutePath() + "] not exists."); }/*w ww.java2 s . co m*/ if (to.exists()) { if (overwrite) { success = to.delete(); if (!success) { throw new IOException("rename from->temp failed. from=[" + from.getAbsolutePath() + "]"); } } else { throw new IOException("file to=" + to.getAbsolutePath() + "] already exists."); } } success = from.renameTo(to); if (!success) { throw new IOException("rename from->temp failed. from=[" + from.getAbsolutePath() + "]"); } } }