Here you can find the source of renameFileHard(File srcFile, File destFile)
public static boolean renameFileHard(File srcFile, File destFile) throws IOException
//package com.java2s; /*//from ww w.j a v a 2s .c om * $Id$ * -------------------------------------------------------------------------------------- * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com * * The software in this package is published under the terms of the CPAL v1.0 * license, a copy of which has been included with this distribution in the * LICENSE.txt file. */ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { /** * @see org.mule.util.FileUtils#renameFileHard */ public static boolean renameFileHard(File srcFile, File destFile) throws IOException { boolean isRenamed = false; if (srcFile != null && destFile != null) { if (!destFile.exists()) { if (srcFile.isFile()) { FileInputStream in = null; FileOutputStream out = null; try { in = new FileInputStream(srcFile); out = new FileOutputStream(destFile); out.getChannel().transferFrom(in.getChannel(), 0, srcFile.length()); isRenamed = true; } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } if (isRenamed) { srcFile.delete(); } else { destFile.delete(); } } } } return isRenamed; } }