Example usage for java.io File renameTo

List of usage examples for java.io File renameTo

Introduction

In this page you can find the example usage for java.io File renameTo.

Prototype

public boolean renameTo(File dest) 

Source Link

Document

Renames the file denoted by this abstract pathname.

Usage

From source file:com.xxg.jdeploy.util.FileUtil.java

/**
 * //from  w ww . j  av  a 2 s. c  o m
 * @param oldFile
 * @param newDir
 * @throws IOException
 */
public static void moveFile(File oldFile, String newDir) throws IOException {
    File newFolder = new File(newDir);
    if (!newFolder.exists())
        newFolder.mkdirs();
    File newFile = new File(newDir + oldFile.getName());
    oldFile.renameTo(newFile);
}

From source file:com.uniteddev.Unity.Downloader.java

public static void renameFiles() throws IOException, InterruptedException {
    Login.progressText.setText("Renaming files...");
    System.out.println("Renaming files...");
    class renameFile implements Runnable {
        private int i;

        renameFile(int i) {
            this.i = i;
        }//from   w ww .  j  a va  2s.c o m

        public void run() {
            //System.out.println("Currently attempting Pool Index: "+this.i);
            String file = rename_files.get(this.i);
            if (file.contains("%20") || file.contains("%5b") || file.contains("%5d")) {
                file = namefix(file);
                File oldfile = new File(Minecraft.getWorkingDirectory(), rename_files.get(this.i));
                if (oldfile.exists()) {
                    File newfile = new File(Minecraft.getWorkingDirectory(), file);
                    oldfile.renameTo(newfile);
                    System.out.println("Renamed " + oldfile.getName() + " to " + newfile.getName());
                }
            }

        }
    }
    ExecutorService pool = Executors.newFixedThreadPool(cores + 4);
    for (int i = 0; i < rename_files.size(); i++) {
        pool.submit(new renameFile(i));
    }
    pool.shutdown();
    pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}

From source file:com.dnielfe.manager.utils.SimpleUtils.java

public static boolean renameTarget(String filePath, String newName) {
    File src = new File(filePath);

    String temp = filePath.substring(0, filePath.lastIndexOf("/"));
    File dest = new File(temp + "/" + newName);

    if (src.renameTo(dest))
        return true;
    else/*from  w  w w. j  a  va2s  .co m*/
        return false;
}

From source file:net.pocketpixels.hubmanager.DBmanager.java

/**
 *Saves the object in JSON to the given folder and with the given name
 * @param obj The object to be saved/*from w  ww  .jav a  2  s.  c  om*/
 * @param loc the folder to save the object into
 * @param name the name of the file for the object save
 * @return returns if the file saved
 */
public static boolean saveObj(Object obj, File loc, String name) {
    if (!loc.exists()) {
        loc.mkdirs();
    }
    boolean success = true;
    File locStart = new File(loc + HubManager.getFileSep() + name + ".new");
    File locEnd = new File(loc + HubManager.getFileSep() + name);
    try {
        JSonParser.writeValue(locStart, obj);
    } catch (IOException ex) {
        success = false;
    } finally {
        if (success) {
            if (locEnd.exists()) {
                locEnd.delete();
            }
            locStart.renameTo(locEnd);
        }
    }
    return success;
}

From source file:com.robin.utilities.Utilities.java

public static void moveFileAndReplace(final File target, final File destination) {
    if (destination.exists()) {
        Assert.assertTrue(destination.delete(), "Could not delete '" + destination.getAbsolutePath() + "'.");
    }//from w  ww.j a  v  a 2  s  . c  om
    Assert.assertTrue(target.renameTo(destination),
            "Could not move '" + target.getAbsolutePath() + "' to '" + destination.getAbsolutePath() + "'.");
}

From source file:com.symbian.driver.core.processors.EmulatorPreProcessor.java

/**
 * @param lEmulatorHashBackup//w  w w  . j av a 2 s.c  o  m
 * 
 * @deprecated This needs to use the emulator ROM tool
 */
public static void restoreEmulator(HashMap<File, File> lEmulatorHashBackup) {
    if (lEmulatorHashBackup != null) {
        for (File lEmulatorOrginal : lEmulatorHashBackup.keySet()) {
            File lEmulatorBackup = lEmulatorHashBackup.get(lEmulatorOrginal);

            if (lEmulatorBackup != null && !lEmulatorBackup.renameTo(lEmulatorOrginal)) {
                LOGGER.fine("Could not restore Emulator backup of: " + lEmulatorBackup.toString() + " to "
                        + lEmulatorOrginal.toString());
            }
        }
    }
}

From source file:net.mybox.mybox.Common.java

public static boolean renameLocal(String oldPath, String newPath) {
    System.out.println("Renaming local item " + oldPath + " to " + newPath);

    File oldFile = new File(oldPath);
    File newFile = new File(newPath);

    return (oldFile.renameTo(newFile));

    //      System.out.println("Error durring rename");
}

From source file:com.sfs.jbtimporter.JBTImporter.java

/**
 * Revert the issues to the old format./*from   w w  w  . java  2  s . co m*/
 *
 * @param jbt the jbt processor
 * @param issues the issues
 */
private static void revertIssues(final JBTProcessor jbt, final List<JBTIssue> issues) {

    for (JBTIssue issue : issues) {
        System.out.println("Reverting Issue ID: " + issue.getId());
        System.out.println("Filename: " + issue.getFullFileName());

        // Read the XML file
        final File xmlFile = new File(issue.getFullFileName());
        final File originalFile = new File(issue.getFullFileName() + ".old");

        if (originalFile.exists()) {
            // Rename the old file to the original file
            originalFile.renameTo(xmlFile);
        }
        System.out.println("-------------------------------------");
    }
}

From source file:Main.java

public static void rename(File from, File to, boolean delete) {
    if (!from.exists()) {
        return;/*  w w w. ja v a 2s .com*/
    }
    boolean isRename = false;
    if (to.exists()) {
        if (delete) {
            to.delete();
            isRename = true;
        } else {
            isRename = false;
        }
    } else {
        isRename = true;
    }
    if (isRename) {
        File parent = to.getParentFile();
        if (!parent.exists()) {
            parent.mkdirs();
        }
        from.renameTo(to);
    }
}

From source file:net.sf.jabref.logic.util.io.FileUtil.java

/**
 * @param fileName/*from w w  w  .  ja v a 2s  . c o m*/
 * @param destFilename
 * @return
 */
public static boolean renameFile(String fileName, String destFilename) {
    // File (or directory) with old name
    File fromFile = new File(fileName);

    // File (or directory) with new name
    File toFile = new File(destFilename);

    // Rename file (or directory)
    return fromFile.renameTo(toFile);
}