List of usage examples for java.io File renameTo
public boolean renameTo(File dest)
From source file:com.owncloud.android.operations.RenameFileOperation.java
private void saveLocalDirectory() { mStorageManager.moveDirectory(mFile, mNewRemotePath); String localPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile); File localDir = new File(localPath); if (localDir.exists()) { localDir.renameTo(new File(FileStorageUtils.getSavePath(mAccount.name) + mNewRemotePath)); // TODO - if renameTo fails, children files that are already down will result unlinked }/*from ww w . jav a2s . com*/ }
From source file:org.jasig.ssp.util.importer.job.tasklet.BatchInitializer.java
private void copyDeleteFiles(File processDirectory) throws IOException { for (Resource resource : resources) { File file = resource.getFile(); logger.info("Move file from " + file.getPath() + " to " + processDirectory.getPath()); file.renameTo(new File(processDirectory, file.getName())); }//from w w w. j av a 2 s. c o m }
From source file:gov.redhawk.efs.sca.server.internal.FileSystemImpl.java
@Override public void move(final String sourceFileName, final String destinationFileName) throws InvalidFileName, FileException { if (sourceFileName.equals(destinationFileName)) { throw new InvalidFileName(ErrorNumberType.CF_EINVAL, "Source file must be different from destination file."); }// www.jav a 2 s. c o m final File sourceFile = new File(this.root, sourceFileName); if (!sourceFile.renameTo(new File(this.root, destinationFileName))) { throw new FileException(ErrorNumberType.CF_EIO, "Failed to move."); } }
From source file:cc.recommenders.io.Directory.java
public WritingArchive reopenWritingArchive(String fileName, Type classOfT) throws IOException { String tmpFileName = createTempFile(fileName); tmpFileName = tmpFileName.replace('-', '_'); if (!exists(fileName) || exists(tmpFileName)) { throw Throws.throwIllegalArgumentException("file does not exists or name collision of tmpfile"); }/*from w w w.j a v a2 s.c o m*/ File old = new File(rootDir, fileName); File tmp = new File(rootDir, tmpFileName); old.renameTo(tmp); IReadingArchive oldArchive = getReadingArchive(tmpFileName); WritingArchive newArchive = getWritingArchive(fileName); while (oldArchive.hasNext()) { Object o = oldArchive.getNext(classOfT); newArchive.add(o); } oldArchive.close(); tmp.delete(); return newArchive; }
From source file:net.sourceforge.metware.binche.loader.OfficialChEBIOboLoader.java
/** * The constructor loads the OBO file from the ChEBI ftp and executes the reasoning steps. * * @throws IOException//from www . ja va 2s . c o m * @throws BackingStoreException */ public OfficialChEBIOboLoader() throws IOException, BackingStoreException { Preferences binchePrefs = Preferences.userNodeForPackage(BiNChe.class); if (binchePrefs.keys().length == 0) { binchePrefs = (new DefaultPreferenceSetter()).getDefaultSetPrefs(); } PreProcessOboFile ppof = new PreProcessOboFile(); File tmpFileObo = File.createTempFile("BiNChE", ".obo"); FileUtils.copyURLToFile(new URL(oboURL), tmpFileObo); ppof.getTransitiveClosure(tmpFileObo.getAbsolutePath(), binchePrefs.get(BiNChEOntologyPrefs.RoleOntology.name(), null), false, true, BiNChEOntologyPrefs.RoleOntology.getRootChEBIEntries(), Arrays.asList("rdfs:label"), new ArrayList<String>()); File tmpRoleOnt = new File(binchePrefs.get(BiNChEOntologyPrefs.RoleOntology.name(), null) + ".temp"); tmpRoleOnt.delete(); ppof.getTransitiveClosure(tmpFileObo.getAbsolutePath(), binchePrefs.get(BiNChEOntologyPrefs.StructureOntology.name(), null), false, false, BiNChEOntologyPrefs.StructureOntology.getRootChEBIEntries(), Arrays.asList("rdfs:label", "InChI"), new ArrayList<String>()); File tmpStructOnt = new File(binchePrefs.get(BiNChEOntologyPrefs.StructureOntology.name(), null) + ".temp"); tmpStructOnt.delete(); ppof.getTransitiveClosure(tmpFileObo.getAbsolutePath(), binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null), true, true, BiNChEOntologyPrefs.RoleAndStructOntology.getRootChEBIEntries(), Arrays.asList("rdfs:label", "InChI"), Arrays.asList("http://purl.obolibrary.org/obo/RO_0000087")); File tmpStructRoleOnt = new File( binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null) + ".temp"); tmpStructRoleOnt.delete(); File structRoleAnnot = new File( binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null).replace(".obo", ".txt")); String fullPath = binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null); structRoleAnnot.renameTo(new File( fullPath.substring(0, fullPath.lastIndexOf(File.separator)) + File.separator + "chebi_roles.anno")); tmpFileObo.delete(); }
From source file:io.stallion.asyncTasks.AsyncTaskFilePersister.java
public boolean markComplete(AsyncTask task) { File file = new File(pathForLocked(task)); File dest = new File(pathForCompleted(task)); boolean succeeded = file.renameTo(dest); if (!succeeded) { return false; }// w ww .ja v a 2s.c o m task.setCompletedAt(DateUtils.mils()); persist(task); return true; }
From source file:echopoint.tucana.event.DefaultUploadCallback.java
/** * Over-ridden to save the contents of the uploaded file to {@link #directory}. * Client-code should ideally wrap this method in a try-catch clause to * handle file copying errors and update the UI as appropriate. * * {@inheritDoc}/*ww w .j a v a2 s .co m*/ * @throws RuntimeException If errors are encountered while copying the * uploaded file to the specified directory. */ @Override public void uploadSucceeded(final UploadFinishEvent event) { final File temp = getTempFile(); final File file = getFileName(event.getFileName()); try { event.getFileItem().write(temp); if (!temp.renameTo(file)) { final BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); final BufferedInputStream bis = new BufferedInputStream(new FileInputStream(temp)); IOUtils.copy(bis, bos); bis.close(); bos.close(); temp.delete(); logger.log(level, "Rename of temp file to " + file.getAbsolutePath() + " failed. Recopied from source."); } event.getFileItem().delete(); logger.log(level, "Copied upload file contents to: " + file.getAbsolutePath()); } catch (Exception e) { throw new RuntimeException("Error copying uploaded file!", e); } super.uploadSucceeded(event); }
From source file:io.stallion.asyncTasks.AsyncTaskFilePersister.java
public boolean lockForProcessing(AsyncTask task) { Log.fine("Locking task for processing {0}", task.getId()); //String errMessage = String.format("Failed to lock task id=%s class=%s customKey=%s", task.getId(), task.getHandlerName(), task.getCustomKey(); if (task.getLockedAt() > 0) { return false; }//from ww w . j av a 2 s . co m File file = new File(pathForPending(task)); File dest = new File(pathForLocked(task)); boolean succeeded = file.renameTo(dest); if (!succeeded) { return false; } task.setLockedAt(DateUtils.mils()); task.setLockUuid("thread-" + Thread.currentThread().getId()); persist(task); return true; }
From source file:FileBrowserSample.java
/** * Renames a file.// w w w . j av a2s . c o m * * @param file * @param newName * @return the after after being renamed or <code>null</code> if renaming * fails. */ private File renameFile(File file, String newName) { File dest = new File(file.getParentFile(), newName); if (file.renameTo(dest)) { return dest; } else { return null; } }
From source file:de.langmi.spring.batch.examples.complex.file.renamefile.partition.extrastep.RenameFilesTasklet.java
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { for (Entry<String, String> entry : fileNames.entrySet()) { String oldFileName = entry.getKey(); // remove "file:" part, sometimes there due to spring resource patterns if (oldFileName.contains(FILE_PREFIX)) { oldFileName = oldFileName.replace(FILE_PREFIX, ""); }//from ww w .jav a 2 s .c om // old file name File oldFile = new File(oldFileName); String path = oldFile.getParent(); String newFilePathAndName = createOutputFileName(path, entry); // rename file File newFile = new File(newFilePathAndName); oldFile.renameTo(newFile); LOG.info("renamed:" + oldFile.getPath() + " to:" + newFilePathAndName); } return RepeatStatus.FINISHED; }