List of usage examples for org.apache.commons.io FileUtils moveFile
public static void moveFile(File srcFile, File destFile) throws IOException
From source file:net.shopxx.plugin.localStorage.LocalStoragePlugin.java
@Override public void upload(String path, File file, String contentType) { File destFile = new File(servletContext.getRealPath(path)); try {/*from ww w .j a va 2 s . c o m*/ FileUtils.moveFile(file, destFile); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:eu.delving.metadata.Hasher.java
public static File ensureFileHashed(File file) throws IOException { if (file.getName().contains(SEPARATOR)) { return file; } else {/*from w w w . java 2 s.c o m*/ Hasher hasher = new Hasher(); hasher.update(file); File hashedFile = new File(file.getParentFile(), hasher.prefixFileName(file.getName())); if (hashedFile.exists()) FileUtils.deleteQuietly(hashedFile); FileUtils.moveFile(file, hashedFile); return hashedFile; } }
From source file:mesclasses.util.EleveFileUtil.java
public static String moveFileForEleve(Eleve eleve, File file, String type) throws IOException { File eleveDir = getEleveDirWithType(eleve, type); eleveDir.mkdirs();//from w w w . ja v a 2s . c o m String fileName = FilenameUtils.getName(file.getPath()); File newFile = new File(eleveDir.getPath() + File.separator + fileName); if (newFile.exists()) { throw new IOException( "Le fichier " + fileName + " de type " + type + " existe dj pour " + eleve.getFirstName()); } FileUtils.moveFile(file, newFile); return newFile.getPath(); }
From source file:io.openvidu.server.utils.CustomFileManager.java
public void moveFile(String filePath, String newFilePath, boolean deleteFoldersWhileEmpty) { try {//from w ww . j av a2 s. c o m FileUtils.moveFile(FileUtils.getFile(filePath), FileUtils.getFile(newFilePath)); } catch (IOException e) { log.error("Error moving file '{}' to new path '{}': {}", filePath, newFilePath, e.getMessage()); } if (deleteFoldersWhileEmpty) { boolean keepDeleting = true; File folder = new File(filePath).getParentFile(); while (keepDeleting) { if (folder.exists() && folder.isDirectory() && folder.listFiles().length == 0) { folder.delete(); folder = folder.getParentFile(); } else { keepDeleting = false; } } } }
From source file:name.vysoky.xhtml.Corrector.java
public void correct(File xhtmlFile) throws IOException { File tempFile = new File(xhtmlFile.getAbsolutePath() + ".tmp"); FileUtils.moveFile(xhtmlFile, tempFile); process(tempFile, xhtmlFile, "UTF-8"); if (!tempFile.delete()) throw new IOException("Unable to delete temp file '" + tempFile.getAbsolutePath() + "'!"); }
From source file:com.dp2345.plugin.file.FilePlugin.java
@Override public void upload(String path, File file, String contentType) { File destFile = new File(servletContext.getRealPath(path)); try {/*from w ww . j a v a 2s .c o m*/ FileUtils.moveFile(file, destFile); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.zotoh.netio.MemFileServer.java
public void saveFile(String file, StreamData data) throws IOException { File r, fp = new File(_vdir, file); fp.delete();/*from ww w . j a va 2s. c o m*/ if (data.isDiskFile()) { r = data.getFileRef(); // move may fail, should then try copy FileUtils.moveFile(r, fp); } else { StreamUte.writeFile(fp, data.getBytes()); } }
From source file:com.music.service.LocalFileStorageService.java
@Override public void moveFile(String sourcePath, String targetPath) throws IOException { FileUtils.moveFile(new File(sourcePath), new File(targetPath)); }
From source file:com.thoughtworks.go.server.cache.ZipArtifactCache.java
@Override void createCachedFile(ArtifactFolder artifactFolder) throws IOException { File originalFolder = artifactFolder.getRootFolder(); File cachedZip = cachedFile(artifactFolder); File cachedTempZip = zipToTempFile(cachedZip); cachedTempZip.getParentFile().mkdirs(); try {/* w ww . java2 s. c om*/ zipUtil.zip(originalFolder, cachedTempZip, Deflater.DEFAULT_COMPRESSION); } catch (IOException e) { cachedTempZip.delete(); throw e; } FileUtils.moveFile(cachedTempZip, cachedZip); }
From source file:fr.itinerennes.bundler.tasks.framework.AbstractCountedCsvTask.java
@PostExec public void prependLineCount() throws IOException { LOGGER.debug("Inserting line count at file head: {}", lineCount); final File output = getOutputFile(); final File source = File.createTempFile("itr-", output.getName(), output.getParentFile()); source.delete();//from ww w. ja v a 2 s.c om FileUtils.moveFile(output, source); InputStream from = null; BufferedWriter to = null; try { from = new FileInputStream(source); to = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output), CHARSET)); to.write(String.valueOf(lineCount)); to.newLine(); final LineIterator i = IOUtils.lineIterator(from, CHARSET.name()); while (i.hasNext()) { to.write(i.next()); to.newLine(); } } finally { IOUtils.closeQuietly(from); IOUtils.closeQuietly(to); FileUtils.deleteQuietly(source); } }