Java File Rename renameFile(String from, String to, String baksuffix)

Here you can find the source of renameFile(String from, String to, String baksuffix)

Description

rename File

License

Open Source License

Declaration

public static boolean renameFile(String from, String to, String baksuffix) 

Method Source Code

//package com.java2s;
/**/* w  w w  .  j  av a 2  s  .c om*/
 * Title:        efa - elektronisches Fahrtenbuch f?r Ruderer
 * Copyright:    Copyright (c) 2001-2011 by Nicolas Michael
 * Website:      http://efa.nmichael.de/
 * License:      GNU General Public License v2
 *
 * @author Nicolas Michael
 * @version 2
 */

import java.io.*;

public class Main {
    public static boolean renameFile(String from, String to, String baksuffix) {
        try {
            File ffrom = new File(from);
            if (!ffrom.isFile()) {
                return false;
            }
            File fto = new File(to);
            if (fto.isFile()) {
                File fbak = new File(to + baksuffix);
                if (fbak.isFile()) {
                    fbak.delete();
                }
                fto.renameTo(fbak);
            }
            return ffrom.renameTo(fto);
        } catch (Exception e) {
            return false;
        }
    }
}

Related

  1. renameFile(String currentPath, String newPath)
  2. renameFile(String file, String toFile)
  3. renameFile(String fileFrom, String fileTo)
  4. renameFile(String fileName, String destFilename)
  5. renameFile(String filePath, String descFilePath)
  6. renameFile(String fromFilename, String toFilename)
  7. renameFile(String newName, String oldName)
  8. renameFile(String oldFile, String newName)
  9. renameFile(String oldFileName, String newFileName)