Java Utililty Methods File Rename

List of utility methods to do File Rename

Description

The list of methods to do File Rename are organized into topic(s).

Method

voidrenameFile(File src, File dest)
rename File
if (!src.renameTo(dest)) {
    throw new IOException("Failed to rename " + src + " to " + dest);
booleanrenameFile(File src, File dest)
rename File
if (dest.exists()) {
    System.err.println("FileUtils.renameFile: dest exists -- deleting");
    dest.delete();
boolean success = src.renameTo(dest);
if (!success) {
    success = copyFile(src, dest);
    if (success) {
...
voidrenameFile(File src, File dest, boolean overwrite)
rename File
if (dest.exists() && overwrite) {
    dest.delete();
src.renameTo(dest);
booleanrenameFile(File srcFile, File destFile)
rename File
if (srcFile.getAbsolutePath().equals(destFile.getAbsolutePath())) {
    return false;
if (srcFile.getParent().equals(destFile.getParent()) && srcFile.getName().toLowerCase(Locale.getDefault())
        .equals(destFile.getName().toLowerCase(Locale.getDefault()))) {
    File tmpFile = new File(destFile.getParent(), UUID.randomUUID().getLeastSignificantBits() + ".tmp");
    if (!tmpFile.exists()) {
        renameFile(srcFile, tmpFile);
...
voidrenameFile(File srcFile, File dstFile)
Rename file.
if (!srcFile.renameTo(dstFile)) {
    InputStream in = null;
    OutputStream out = null;
    try {
        in = new FileInputStream(srcFile);
        out = new FileOutputStream(dstFile);
        transfer(in, out);
    } catch (IOException ioe) {
...
booleanrenameFile(File srcFile, File renameToFile)
rename File
if (!srcFile.exists()) {
    throw new FileNotFoundException("Source file[" + srcFile.getName() + "] not found");
if (renameToFile.exists()) {
    throw new FileNotFoundException("Target file[" + renameToFile.getName() + "] already exists");
if (!renameToFile.getParentFile().isDirectory()) {
    throw new FileNotFoundException("Target directory[" + renameToFile.getParent() + "] does not exists");
...
FilerenameFile(final File path, final String fname)
Renames a file if the name alread exists.
if (path == null) {
    throw new NullPointerException("path");
if (fname == null) {
    throw new NullPointerException("fname");
final int dotIndex = fname.lastIndexOf('.');
final String prefix = (dotIndex == -1) ? fname : fname.substring(0, dotIndex);
...
booleanrenameFile(final String oldName, final String newName)
rename a file
final File f_old = new File(oldName);
final File f_new = new File(newName);
final boolean ret = f_old.renameTo(f_new);
return ret;
booleanrenameFile(String currentPath, String newPath)
Renames a file
boolean succeeded = false;
try {
    File currentFile = new File(currentPath);
    if (currentFile.exists()) {
        File newFile = new File(newPath);
        succeeded = currentFile.renameTo(newFile);
} catch (Exception e) {
...
voidrenameFile(String file, String toFile)
Rename a file.
File toBeRenamed = new File(file);
if (!toBeRenamed.exists() || toBeRenamed.isDirectory()) {
    System.out.println("File does not exist: " + file);
    return;
File newFile = new File(toFile);
if (!toBeRenamed.renameTo(newFile)) {
    System.out.println("Error renmaing file");
...