Java Rename File rename(File oldFile, File newFile)

Here you can find the source of rename(File oldFile, File newFile)

Description

rename

License

Open Source License

Declaration

public static void rename(File oldFile, File newFile) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.io.IOException;

public class Main {
    public static void rename(File oldFile, File newFile) throws IOException {
        rename(oldFile, newFile, false);
    }//from   ww w.j a  v  a  2s .c o  m

    public static void rename(File oldFile, File newFile, boolean ignoreExisting) throws IOException {
        if (newFile.exists()) {
            if (ignoreExisting)
                return;
            throw new IOException("A file with the name " + newFile.getName() + " already exists");
        }
        boolean success = oldFile.renameTo(newFile);
        if (!success)
            throw new IOException("Could note rename file: " + oldFile.getName() + " to " + newFile.getName()
                    + " in path " + oldFile.getParent());
    }
}

Related

  1. rename(File from, File to)
  2. rename(File from, File to)
  3. rename(File from, File to)
  4. rename(File from, File to)
  5. rename(File from, File to, boolean overwrite)
  6. rename(File pFrom, File pTo)
  7. rename(File pFrom, File pTo, boolean pOverWrite)
  8. rename(File source, File dest)
  9. rename(File source, File target)