List of utility methods to do File Rename
boolean | renameFile(String oldname, String newone) Renames a file from oldname to newone. boolean result = false; File file = new File(oldname); if (file.exists()) { result = file.renameTo(new File(newone)); return result; |
void | renameFile(String oldPath, String newName) rename File File file = new File(oldPath); if (!file.exists()) { return; String newPath = newName; if (file.getParent() != null) { newPath = file.getParent() + File.separator + newName; file.renameTo(new File(newPath)); |
void | renameFile(String oldPath, String newPath) rename File try { File dest = null; if (!oldPath.equals(newPath)) { File file = new File(oldPath); dest = new File(newPath); file.renameTo(dest); } catch (Exception e) { ... |
void | renameFile(String oldPath, String newPath, boolean overwrite) Rename a file from an old path to a new path. boolean done = false; File source = new File(oldPath); File destination = new File(newPath); try { if (destination.exists()) { if (!overwrite) { throw new IOException("'" + newPath + "' already exists"); if (!destination.delete()) { throw new IOException("Could not delete '" + newPath + "'"); if (!source.renameTo(destination)) { throw new IOException("'" + oldPath + "' could not be renamed to '" + newPath + "'"); done = true; } finally { if (done) { source.delete(); |
boolean | renameFile(String origPath, String destPath) Rename a file. File orig = new File(origPath); File dest = new File(destPath); if (!orig.exists() || dest.exists()) return false; return orig.renameTo(dest); |
boolean | renameFile(String path, String newPath) rename File synchronized (path.intern()) { File newFile = new File(newPath); if (newFile.exists()) { return false; File oldFile = new File(path); return oldFile.renameTo(newFile); |