Here you can find the source of rename(File from)
public static File rename(File from) throws IOException, InterruptedException
//package com.java2s; /*/* www.j a v a 2s . co m*/ * Copyright (c) 2014 Eike Stepper (Berlin, Germany) and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Eike Stepper - initial API and implementation */ import java.io.File; import java.io.IOException; public class Main { public static File rename(File from) throws IOException, InterruptedException { File to = new File(from.getParentFile(), from.getName() + "." + System.currentTimeMillis()); rename(from, to); return to; } public static void rename(File from, File to) throws IOException, InterruptedException { if (from.exists()) { // Files.move(Paths.get(from.toString()), Paths.get(to.toString())); for (int i = 0; i < 200; i++) { if (from.renameTo(to)) { return; } Thread.sleep(10); } } throw new IOException( "Could not rename '" + from.getAbsolutePath() + "' to '" + to.getAbsolutePath() + "'"); } }