List of usage examples for java.io File renameTo
public boolean renameTo(File dest)
From source file:com.ryan.ryanreader.common.General.java
/** * /*www. j a v a 2s . com*/ * * @param src * @param dst * @throws IOException */ public static void moveFile(final File src, final File dst) throws IOException { if (!src.renameTo(dst)) { // renameToCOPY copyFile(src, dst); if (!src.delete()) { src.deleteOnExit(); } } }
From source file:com.vmware.identity.interop.PlatformUtils.java
public static boolean renameFile(File oldFile, File newFile) { if (oldFile == null || newFile == null) return false; ;//from ww w.ja v a 2 s .c om boolean renamed = false; if (Platform.isLinux()) { renamed = oldFile.renameTo(newFile); } // On windows, File.renameTo does not actually work, implement a version of our own else if (Platform.isWindows()) { renamed = renameFileOnWindows(oldFile, newFile); } return renamed; }
From source file:com.asakusafw.testdriver.compiler.util.DeploymentUtil.java
private static void move(File source, File destination) throws IOException { prepareDestination(destination);//www . j ava2 s . com boolean success = source.renameTo(destination); if (success == false) { doCopy(source, destination); if (FileUtils.deleteQuietly(source) == false) { LOG.warn(MessageFormat.format("failed to delete moving original file: {0}", source)); } } }
From source file:IO.Files.java
/** * Returns true if the given file is successfully moved to the destination * folder//from w w w . j av a 2s. co m * * @param file source file * @param subFolderName the name of the subfolder to create and move the * file to * @return true if the given file is successfully moved to the destination * folder */ public static boolean MoveFileToSubFolder(File file, String subFolderName) { String filename = file.getName(); File destinationFolder = new File(file.getParent() + "\\" + subFolderName); String destinationFilePath = destinationFolder + "\\" + filename; if (!destinationFolder.exists()) { destinationFolder.mkdir(); } if (file.renameTo(new File(destinationFilePath))) { //System.out.println(String.format("File '%s' is moved successful to folder:\n%s\n", filename, destinationFolder)); return true; } else { //System.out.println(String.format("File '%s' is failed to move to folder: \n%s\n", filename, destinationFolder)); return false; } }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.io.FileUtils.java
/** * Moves the file from one path to another. This method can rename a file or * move it to a different directory, like the Unix {@code mv} command. * * @param source the source file/* w ww.ja va 2s. c o m*/ * @param destination the destination file * @throws IOException if an I/O error occurs */ public static void move(File source, File destination) throws IOException { Validate.notNull(source, "source is null"); Validate.notNull(destination, "destination is null"); if (source.equals(destination)) { return; } if (!source.renameTo(destination)) { copy(source, destination); if (!source.delete()) { if (!destination.delete()) { throw new IOException(MessageFormat.format(UNABLE_TO_DELETE, destination)); } throw new IOException(MessageFormat.format(UNABLE_TO_DELETE, source)); } } }
From source file:edu.ur.file.db.FileSystemManager.java
/** * Rename the file to the new file.//from w w w. j av a 2s . c o m * * @param start the file to move * @param destination destination to move to * @return true if the file is renamed to. */ static boolean renameFile(File start, File destination) { return start.renameTo(destination); }
From source file:Main.java
/** * Rename existing file in same directory if target file exists, delete * Code nicked from http://stackoverflow.com/users/325442/mr-bungle * @param context/* www . j a v a 2 s. c o m*/ * @param originalFileName * @param newFileName */ private static void rename(Context context, String originalFileName, String newFileName) { File originalFile = context.getFileStreamPath(originalFileName); if (originalFile.exists()) { Log.d("SavingHelper", "renaming " + originalFileName + " size " + originalFile.length() + " to " + newFileName); File newFile = new File(originalFile.getParent(), newFileName); if (newFile.exists()) { context.deleteFile(newFileName); } originalFile.renameTo(newFile); } }
From source file:com.stratelia.webactiv.util.fileFolder.FileFolderManager.java
/** * renameFile : modification du nom d'un fichier Param = chemin du fichier *///from w ww .j av a 2 s .c om public static void renameFile(String cheminRep, String name, String newName) throws UtilException { /* ex chemin = c:\\j2sdk\\public_html\\WAUploads\\WA0webSite10\\nomSite */ File file = new File(cheminRep, name); if (file.isFile()) { File newFile = new File(cheminRep, newName); if (!file.renameTo(newFile)) { SilverTrace.error("util", "FileFolderManager.renameFile", "util.EX_RENAME_FILE_ERROR", name + " en " + cheminRep + "\\" + newName); throw new UtilException("FileFolderManager.renameFile", "util.EX_RENAME_FILE_ERROR", name + " en " + cheminRep + "\\" + newName); } } else { SilverTrace.error("util", "FileFolderManager.renameFile", "util.EX_NO_CHEMIN_FINCHER", cheminRep + "\\" + name); throw new UtilException("fileFolderManager.renameFile", "util.EX_NO_CHEMIN_FINCHER", cheminRep + "\\" + name); } }
From source file:com.stratelia.webactiv.util.fileFolder.FileFolderManager.java
/** * renameFolder : modification du nom d'un repertoire Param = chemin du repertoire *//*w ww .j av a 2 s . co m*/ public static void renameFolder(String cheminRep, String newCheminRep) throws UtilException { /* ex chemin = c:\\j2sdk\\public_html\\WAUploads\\WA0webSite10\\nomSite */ File directory = new File(cheminRep); if (directory.isDirectory()) { File newDirectory = new File(newCheminRep); if (!directory.renameTo(newDirectory)) { SilverTrace.error("util", "FileFolderManager.renameFolder", "util.EX_REPOSITORY_RENAME", cheminRep + " en " + newCheminRep); throw new UtilException("FileFolderManager.renameFolder", "util.EX_REPOSITORY_RENAME", cheminRep + " en " + newCheminRep); } } else { SilverTrace.error("util", "FileFolderManager.renameFolder", "util.EX_NO_CHEMIN_REPOS", cheminRep); throw new UtilException("FileFolderManager.renameFolder", "util.EX_NO_CHEMIN_REPOS", cheminRep); } }
From source file:Main.java
public static boolean renameFile(File file, String newFileName) { if (newFileName.matches(FILENAME_REGIX)) { File newFile = null;//from w w w . j a va 2s . c om if (file.isDirectory()) { newFile = new File(file.getParentFile(), newFileName); } else { String temp = newFileName + file.getName().substring(file.getName().lastIndexOf('.')); newFile = new File(file.getParentFile(), temp); } if (file.renameTo(newFile)) { return true; } } return false; }