@Test public void testRenameFile_AlreadyExists() throws Exception { File src = TempFileUtils.createTrackedFile(this); src.createNewFile(); File wipFile = new File(src.getCanonicalPath() + ".wip"); wipFile.createNewFile(); TempFileUtils.trackFile(wipFile, this); File renamed = renameFile(src, ".wip", new StandardWorker()); assertNotEquals(wipFile, renamed); assertFalse(src.exists()); assertTrue(wipFile.exists()); assertTrue(renamed.exists()); }
public static File renameFile(File file, String suffix, FsWorker worker) throws FsException { File newFile = new File(file.getAbsolutePath() + suffix); try { worker.rename(file, newFile); } catch (FsFilenameExistsException e) { newFile = new File(file.getParentFile(), System.currentTimeMillis() + "." + file.getName() + suffix); worker.rename(file, newFile); } return newFile; }
FsHelper { public static File renameFile(File file, String suffix, FsWorker worker) throws FsException { File newFile = new File(file.getAbsolutePath() + suffix); try { worker.rename(file, newFile); } catch (FsFilenameExistsException e) { newFile = new File(file.getParentFile(), System.currentTimeMillis() + "." + file.getName() + suffix); worker.rename(file, newFile); } return newFile; } }
FsHelper { public static File renameFile(File file, String suffix, FsWorker worker) throws FsException { File newFile = new File(file.getAbsolutePath() + suffix); try { worker.rename(file, newFile); } catch (FsFilenameExistsException e) { newFile = new File(file.getParentFile(), System.currentTimeMillis() + "." + file.getName() + suffix); worker.rename(file, newFile); } return newFile; }  }
FsHelper { public static File renameFile(File file, String suffix, FsWorker worker) throws FsException { File newFile = new File(file.getAbsolutePath() + suffix); try { worker.rename(file, newFile); } catch (FsFilenameExistsException e) { newFile = new File(file.getParentFile(), System.currentTimeMillis() + "." + file.getName() + suffix); worker.rename(file, newFile); } return newFile; }  static File toFile(String s); static File createFileReference(URL url); static File createFileReference(URL url, String charset); @Deprecated static URL createUrlFromString(String s); static URL createUrlFromString(String s, boolean backslashConvert); static FileFilter createFilter(String filterExpression, String filterImpl); static FileFilter logWarningIfRequired(FileFilter f); static File renameFile(File file, String suffix, FsWorker worker); }
FsHelper { public static File renameFile(File file, String suffix, FsWorker worker) throws FsException { File newFile = new File(file.getAbsolutePath() + suffix); try { worker.rename(file, newFile); } catch (FsFilenameExistsException e) { newFile = new File(file.getParentFile(), System.currentTimeMillis() + "." + file.getName() + suffix); worker.rename(file, newFile); } return newFile; }  static File toFile(String s); static File createFileReference(URL url); static File createFileReference(URL url, String charset); @Deprecated static URL createUrlFromString(String s); static URL createUrlFromString(String s, boolean backslashConvert); static FileFilter createFilter(String filterExpression, String filterImpl); static FileFilter logWarningIfRequired(FileFilter f); static File renameFile(File file, String suffix, FsWorker worker);  }