本文整理了Java中org.apache.commons.io.FileUtils.copyFile()
方法的一些代码示例,展示了FileUtils.copyFile()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.copyFile()
方法的具体详情如下:
包路径:org.apache.commons.io.FileUtils
类名称:FileUtils
方法名:copyFile
[英]Copies a file to a new location preserving the file date.
This method copies the contents of the specified source file to the specified destination file. The directory holding the destination file is created if it does not exist. If the destination file exists, then this method will overwrite it.
Note: This method tries to preserve the file's last modified date/times using File#setLastModified(long), however it is not guaranteed that the operation will succeed. If the modification operation fails, no indication is provided.
[中]将文件复制到保留文件日期的新位置。
此方法将指定源文件的内容复制到指定目标文件。如果目标文件不存在,将创建保存该文件的目录。如果目标文件存在,则此方法将覆盖它。
注意:此方法尝试使用file#setlastmedited(long)保留文件的上次修改日期/时间,但不能保证操作会成功。如果修改操作失败,则不提供任何指示。
代码示例来源:origin: apache/incubator-pinot
private void copyStarTreeV2(File src, File dest)
throws IOException {
File indexFile = new File(src, StarTreeV2Constants.INDEX_FILE_NAME);
if (indexFile.exists()) {
FileUtils.copyFile(indexFile, new File(dest, StarTreeV2Constants.INDEX_FILE_NAME));
FileUtils.copyFile(new File(src, StarTreeV2Constants.INDEX_MAP_FILE_NAME),
new File(dest, StarTreeV2Constants.INDEX_MAP_FILE_NAME));
}
}
代码示例来源:origin: apache/incubator-pinot
@Override
public void fetchSegmentToLocal(String uri, File tempFile)
throws Exception {
FileUtils.copyFile(new File(uri), tempFile);
LOGGER.info("Copy file from {} to {}; Length of file: {}", uri, tempFile, tempFile.length());
}
代码示例来源:origin: commons-io/commons-io
throw new NullPointerException("Destination must not be null");
if (!srcFile.exists()) {
throw new FileNotFoundException("Source '" + srcFile + "' does not exist");
throw new IOException("Source '" + srcFile + "' is a directory");
if (destFile.exists()) {
throw new FileExistsException("Destination '" + destFile + "' already exists");
copyFile(srcFile, destFile);
if (!srcFile.delete()) {
FileUtils.deleteQuietly(destFile);
代码示例来源:origin: SonarSource/sonarqube
private void downloadRelease(Release release) throws URISyntaxException, IOException {
String url = release.getDownloadUrl();
URI uri = new URI(url);
if (url.startsWith("file:")) {
// used for tests
File file = toFile(uri.toURL());
copyFileToDirectory(file, downloadDir);
} else {
String filename = substringAfterLast(uri.getPath(), "/");
if (!filename.endsWith("." + PLUGIN_EXTENSION)) {
filename = release.getKey() + "-" + release.getVersion() + "." + PLUGIN_EXTENSION;
}
File targetFile = new File(downloadDir, filename);
File tempFile = new File(downloadDir, filename + "." + TMP_SUFFIX);
downloader.download(uri, tempFile);
copyFile(tempFile, targetFile);
deleteQuietly(tempFile);
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Replaces jenkins.war by the given file.
*
* <p>
* On some system, most notably Windows, a file being in use cannot be changed,
* so rewriting {@code jenkins.war} requires some special trick. Override this method
* to do so.
*/
public void rewriteHudsonWar(File by) throws IOException {
File dest = getHudsonWar();
// this should be impossible given the canRewriteHudsonWar method,
// but let's be defensive
if(dest==null) throw new IOException("jenkins.war location is not known.");
// backing up the old jenkins.war before it gets lost due to upgrading
// (newly downloaded jenkins.war and 'backup' (jenkins.war.tmp) are the same files
// unless we are trying to rewrite jenkins.war by a backup itself
File bak = new File(dest.getPath() + ".bak");
if (!by.equals(bak))
FileUtils.copyFile(dest, bak);
FileUtils.copyFile(by, dest);
// we don't want to keep backup if we are downgrading
if (by.equals(bak)&&bak.exists())
bak.delete();
}
代码示例来源:origin: gocd/gocd
private static void copyPluginAssets() throws IOException {
File classPathRoot = new File(DevelopmentServer.class.getProtectionDomain().getCodeSource().getLocation().getPath());
FileUtils.copyFile(new File("webapp/WEB-INF/rails/webpack/rails-shared/plugin-endpoint.js"), new File(classPathRoot, "plugin-endpoint.js"));
}
代码示例来源:origin: mpetazzoni/ttorrent
} catch (Exception ex) {
logger.error("An error occurred while moving file to its final location", ex);
if (this.target.exists()) {
throw new IOException("Was unable to delete existing file " + target.getAbsolutePath(), ex);
FileUtils.copyFile(this.current, this.target);
代码示例来源:origin: apache/zeppelin
public synchronized void copyLocalDependency(String srcPath, File destPath)
throws IOException {
if (StringUtils.isBlank(srcPath)) {
return;
}
File srcFile = new File(srcPath);
File destFile = new File(destPath, srcFile.getName());
if (!destFile.exists() || !FileUtils.contentEquals(srcFile, destFile)) {
FileUtils.copyFile(srcFile, destFile);
logger.debug("copy {} to {}", srcFile.getAbsolutePath(), destPath);
}
}
代码示例来源:origin: apache/kylin
private void copyNative(String localFile, String destDir) throws IOException {
File src = new File(localFile);
File dest = new File(destDir, src.getName());
FileUtils.copyFile(src, dest);
}
代码示例来源:origin: syncany/syncany
@Override
public void download(RemoteFile remoteFile, File localFile) throws StorageException {
connect();
File repoFile = getRemoteFile(remoteFile);
if (!repoFile.exists()) {
throw new StorageFileNotFoundException("No such file in local repository: " + repoFile);
}
try {
File tempLocalFile = createTempFile("local-tm-download");
tempLocalFile.deleteOnExit();
FileUtils.copyFile(repoFile, tempLocalFile);
localFile.delete();
FileUtils.moveFile(tempLocalFile, localFile);
tempLocalFile.delete();
}
catch (IOException ex) {
throw new StorageException("Unable to copy file " + repoFile + " from local repository to " + localFile, ex);
}
}
代码示例来源:origin: commons-io/commons-io
throw new NullPointerException("Destination must not be null");
if (destDir.exists() && destDir.isDirectory() == false) {
throw new IllegalArgumentException("Destination '" + destDir + "' is not a directory");
final File destFile = new File(destDir, srcFile.getName());
copyFile(srcFile, destFile, preserveFileDate);
代码示例来源:origin: Meituan-Dianping/walle
private void generateChannelApk(final File inputFile, final File outputDir, final String channel) {
final String name = FilenameUtils.getBaseName(inputFile.getName());
final String extension = FilenameUtils.getExtension(inputFile.getName());
final String newName = name + "_" + channel + "." + extension;
final File channelApk = new File(outputDir, newName);
try {
FileUtils.copyFile(inputFile, channelApk);
ChannelWriter.put(channelApk, channel, extraInfo);
} catch (IOException | SignatureNotFoundException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: iBotPeaches/Apktool
private void buildManifestFile(File appDir, File manifest, File manifestOriginal)
throws AndrolibException {
// If we decoded in "raw", we cannot patch AndroidManifest
if (new File(appDir, "resources.arsc").exists()) {
return;
}
if (manifest.isFile() && manifest.exists()) {
try {
if (manifestOriginal.exists()) {
manifestOriginal.delete();
}
FileUtils.copyFile(manifest, manifestOriginal);
ResXmlPatcher.fixingPublicAttrsInProviderAttributes(manifest);
} catch (IOException ex) {
throw new AndrolibException(ex.getMessage());
}
}
}
代码示例来源:origin: Meituan-Dianping/walle
private void generateChannelApk(final File inputFile, final File outputDir, final String channel, final String alias, final Map<String, String> extraInfo) {
final String channelName = alias == null ? channel : alias;
final String name = FilenameUtils.getBaseName(inputFile.getName());
final String extension = FilenameUtils.getExtension(inputFile.getName());
final String newName = name + "_" + channelName + "." + extension;
final File channelApk = new File(outputDir, newName);
try {
FileUtils.copyFile(inputFile, channelApk);
ChannelWriter.put(channelApk, channel, extraInfo);
} catch (IOException | SignatureNotFoundException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: apache/zeppelin
public List<File> load(String artifact, Collection<String> excludes, File destPath)
throws RepositoryException, IOException {
List<File> libs = new LinkedList<>();
if (StringUtils.isNotBlank(artifact)) {
libs = load(artifact, excludes);
for (File srcFile : libs) {
File destFile = new File(destPath, srcFile.getName());
if (!destFile.exists() || !FileUtils.contentEquals(srcFile, destFile)) {
FileUtils.copyFile(srcFile, destFile);
logger.debug("copy {} to {}", srcFile.getAbsolutePath(), destPath);
}
}
}
return libs;
}
代码示例来源:origin: galenframework/galen
public void copyAllFilesTo(File dir) throws IOException {
for (Map.Entry<String, File> entry : files.entrySet()) {
FileUtils.copyFile(entry.getValue(), new File(dir.getAbsolutePath() + File.separator + entry.getKey()));
}
for (FileTempStorage storage : childStorages) {
storage.copyAllFilesTo(dir);
}
}
代码示例来源:origin: apache/incubator-pinot
@Override
public boolean copy(URI srcUri, URI dstUri)
throws IOException {
File srcFile = new File(decodeURI(srcUri.getRawPath()));
File dstFile = new File(decodeURI(dstUri.getRawPath()));
if (dstFile.exists()) {
FileUtils.deleteQuietly(dstFile);
}
if (srcFile.isDirectory()) {
// Throws Exception on failure
FileUtils.copyDirectory(srcFile, dstFile);
} else {
// Will create parent directories, throws Exception on failure
FileUtils.copyFile(srcFile, dstFile);
}
return true;
}
代码示例来源:origin: jenkinsci/jenkins
/**
* On Windows, jenkins.war is locked, so we place a new version under a special name,
* which is picked up by the service wrapper upon restart.
*/
@Override
public void rewriteHudsonWar(File by) throws IOException {
File dest = getHudsonWar();
// this should be impossible given the canRewriteHudsonWar method,
// but let's be defensive
if(dest==null) throw new IOException("jenkins.war location is not known.");
// backing up the old jenkins.war before its lost due to upgrading
// unless we are trying to rewrite jenkins.war by a backup itself
File bak = new File(dest.getPath() + ".bak");
if (!by.equals(bak))
FileUtils.copyFile(dest, bak);
String baseName = dest.getName();
baseName = baseName.substring(0,baseName.indexOf('.'));
File baseDir = getBaseDir();
File copyFiles = new File(baseDir,baseName+".copies");
try (FileWriter w = new FileWriter(copyFiles, true)) {
w.write(by.getAbsolutePath() + '>' + getHudsonWar().getAbsolutePath() + '\n');
}
}
代码示例来源:origin: alibaba/mdrill
/**
* Copy jarstormrootĿ¼
*
* @param conf
* @param tmpJarLocation
* @param stormroot
* @throws IOException
*/
private void setupJar(Map<Object, Object> conf, String tmpJarLocation,
String stormroot) throws IOException {
File srcFile = new File(tmpJarLocation);
if (!srcFile.exists()) {
throw new IllegalArgumentException(tmpJarLocation + " to copy to "
+ stormroot + " does not exist!");
}
String path = StormConfig.masterStormjarPath(stormroot);
File destFile = new File(path);
FileUtils.copyFile(srcFile, destFile);
}
代码示例来源:origin: apache/geode
private void takeScreenshot(String screenshotName) {
WebDriver driver = this.webDriverSupplier.get();
if (driver instanceof TakesScreenshot) {
File tempFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
try {
File screenshot = new File("build/screenshots/" + screenshotName + ".png");
FileUtils.copyFile(tempFile, screenshot);
System.err.println("Screenshot saved to: " + screenshot.getCanonicalPath());
} catch (IOException e) {
throw new Error(e);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!