Java Rename File renameTo(File from, File to, boolean deleteDestination)

Here you can find the source of renameTo(File from, File to, boolean deleteDestination)

Description

rename To

License

Apache License

Declaration

public static void renameTo(File from, File to, boolean deleteDestination) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;

import java.io.IOException;

public class Main {
    public static void renameTo(File from, File to, boolean deleteDestination) throws IOException {
        if (deleteDestination) {
            deleteIfExists(to);/*from   w  w w .j  ava 2s . c o m*/
        }
        if (!from.renameTo(to)) {
            throw new IOException();
        }
    }

    public static void deleteIfExists(File file) throws IOException {
        if (file.exists() && !file.delete()) {
            throw new IOException("delete failed");
        }
    }
}

Related

  1. renameOldFile(final String fileName)
  2. renameOverwrite(String oldname, String newname)
  3. renameSuffix(File f, String suffix)
  4. renameTempDMLScript(String dmlScriptFile)
  5. renameTo(File currentFile, String newName)
  6. renameTo(File fromFile, File toFile)
  7. renameTo(File orig, File dest)
  8. renameTo(File source, String newName)
  9. renameTo(final File srcFile, final File dstfile)