Java Rename File rename(String fileName, String distFile)

Here you can find the source of rename(String fileName, String distFile)

Description

rename

License

Apache License

Declaration

public static boolean rename(String fileName, String distFile) 

Method Source Code


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

import java.io.*;

public class Main {
    public static boolean rename(String fileName, String distFile) {
        synchronized (fileName) {
            File oldFile = new File(fileName);
            if (oldFile.exists()) {
                try {
                    oldFile.renameTo(new File(distFile));
                    return true;
                } catch (Exception e) {
                    e.printStackTrace();
                    return false;
                }/*from   w w  w  .  j a  v  a 2 s. c  o m*/
            } else {
                return true;
            }
        }
    }
}

Related

  1. rename(File src, File dest)
  2. rename(File src, String name)
  3. rename(File srcFile, String newName)
  4. rename(final String src, final String dst)
  5. rename(String existingFile, String newFilename)
  6. rename(String from, String to)
  7. rename(String oldFile, String newFile)
  8. rename(String oldName, String newName)
  9. reName(String oldName, String newName)