Java tutorial
//package com.java2s; import java.io.File; public class Main { public static void rename(String from, String to, boolean delete) { rename(new File(from), new File(to), delete); } public static void rename(File from, File to, boolean delete) { if (!from.exists()) { return; } boolean isRename = false; if (to.exists()) { if (delete) { to.delete(); isRename = true; } else { isRename = false; } } else { isRename = true; } if (isRename) { File parent = to.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } from.renameTo(to); } } }