org.apache.commons.io.FileUtils.copyDirectoryToDirectory()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(248)

本文整理了Java中org.apache.commons.io.FileUtils.copyDirectoryToDirectory()方法的一些代码示例,展示了FileUtils.copyDirectoryToDirectory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.copyDirectoryToDirectory()方法的具体详情如下:
包路径:org.apache.commons.io.FileUtils
类名称:FileUtils
方法名:copyDirectoryToDirectory

FileUtils.copyDirectoryToDirectory介绍

[英]Copies a directory to within another directory preserving the file dates.

This method copies the source directory and all its contents to a directory of the same name in the specified destination directory.

The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.

Note: This method tries to preserve the files' last modified date/times using File#setLastModified(long), however it is not guaranteed that those operations will succeed. If the modification operation fails, no indication is provided.
[中]将目录复制到另一个目录中,保留文件日期。
此方法将源目录及其所有内容复制到指定目标目录中同名的目录中。
如果目标目录不存在,则创建该目录。如果目标目录确实存在,则此方法将源目录与目标目录合并,源目录优先。
注意:此方法尝试使用文件#setlastmedited(long)保留文件的上次修改日期/时间,但不能保证这些操作会成功。如果修改操作失败,则不提供任何指示。

代码示例

代码示例来源:origin: gocd/gocd

private static void copyDbFiles() throws IOException {
  FileUtils.copyDirectoryToDirectory(new File("db/migrate/h2deltas"), new File("db/"));
  if (!new File("db/h2db/cruise.h2.db").exists()) {
    FileUtils.copyDirectoryToDirectory(new File("db/dbtemplate/h2db"), new File("db/"));
  }
}

代码示例来源:origin: commons-io/commons-io

copyFileToDirectory(src, destDir);
} else if (src.isDirectory()) {
  copyDirectoryToDirectory(src, destDir);
} else {
  throw new IOException("The source " + src + " does not exist");

代码示例来源:origin: commons-io/commons-io

@Test
public void testCopyDirectoryToItself() throws Exception {
  final File dir = new File(getTestDirectory(), "itself");
  dir.mkdirs();
  FileUtils.copyDirectoryToDirectory(dir, dir);
  assertEquals(1, LIST_WALKER.list(dir).size());
}

代码示例来源:origin: commons-io/commons-io

final File actualDestDir = new File(destDir, srcDir.getName());
FileUtils.copyDirectoryToDirectory(srcDir, destDir);

代码示例来源:origin: apache/flink

LOG.info("copying the final files from {} to {}", src.getAbsolutePath(), target.getAbsolutePath());
try {
  FileUtils.copyDirectoryToDirectory(src, target);
} catch (IOException e) {
  LOG.warn("Error copying the final files from {} to {}: msg: {}", src.getAbsolutePath(), target.getAbsolutePath(), e.getMessage(), e);

代码示例来源:origin: apache/kylin

logger.info("Start to extract kylin conf files.");
try {
  FileUtils.copyDirectoryToDirectory(new File(ToolUtil.getConfFolder()), exportDir);
} catch (Exception e) {
  logger.warn("Error in export conf.", e);

代码示例来源:origin: apache/incubator-pinot

FileUtils.deleteQuietly(sizeTestDirectory);
FileUtils.copyDirectoryToDirectory(segmentDirectory.getPath().toFile(), sizeTestDirectory);
SegmentDirectory sizeSegment =
  SegmentLocalFSDirectory.createFromLocalFS(sizeTestDirectory, metadata, ReadMode.mmap);
File v3SizeDir = new File(sizeTestDirectory, SegmentDirectoryPaths.V3_SUBDIRECTORY_NAME);
FileUtils.copyDirectoryToDirectory(segmentDirectory.getPath().toFile(), v3SizeDir);
SegmentDirectory sizeV3Segment = SegmentDirectory.createFromLocalFS(v3SizeDir, metadata, ReadMode.mmap);
Assert.assertEquals(sizeSegment.getDiskSizeBytes(), sizeV3Segment.getDiskSizeBytes());

代码示例来源:origin: apache/incubator-pinot

FileUtils.copyDirectoryToDirectory(configFiles.get(2).getParentFile(), new File("."));

代码示例来源:origin: e-biz/androidkickstartr

private void copyLibraryToProject(String lib) {
  try {
    File library = fileHelper.getLibraryFile(lib);
    File projectDir = fileHelper.getFinalDir();
    FileUtils.copyDirectoryToDirectory(library, projectDir);
  } catch (IOException e) {
    LOGGER.error("a problem occured during the copy of the library " + lib, e);
  }
}

代码示例来源:origin: mulesoft/mule

protected void deployDomain(String domain) {
 File domainFile = new File(domain);
 verify(domainFile.exists(), "Domain does not exist: %s", domain);
 try {
  if (domainFile.isDirectory()) {
   copyDirectoryToDirectory(domainFile, this.domainsDir);
  } else {
   copyFileToDirectory(domainFile, this.domainsDir);
  }
 } catch (IOException e) {
  throw new MuleControllerException(format(DOMAIN_DEPLOY_ERROR, domain), e);
 }
}

代码示例来源:origin: mulesoft/mule

public void deploy(String path) {
 File app = new File(path);
 verify(app.exists(), "File does not exists: %s", app);
 verify(app.canRead(), "Cannot read file: %s", app);
 try {
  if (app.isFile()) {
   copyFileToDirectory(app, appsDir);
  } else {
   copyDirectoryToDirectory(app, appsDir);
  }
 } catch (IOException e) {
  throw new MuleControllerException("Could not deploy app [" + path + "] to [" + appsDir + "]", e);
 }
}

代码示例来源:origin: OneBusAway/onebusaway-application-modules

/**
 * Copy the sourceDirectory to the given destinationDirectory
 */
public void copyDir(String sourceDirectoryPath, String destinationDirectoryPath) throws IOException{
 File sourceDir = new File(sourceDirectoryPath);
 File destinationDir = new File(destinationDirectoryPath);
 FileUtils.copyDirectoryToDirectory(sourceDir, destinationDir);
}

代码示例来源:origin: org.bitbucket.iamkenos/cissnei-commons

public static boolean copyDirs(File source, File dest) {
  try {
    org.apache.commons.io.FileUtils.copyDirectoryToDirectory(source, dest);
    return true;
  } catch (Exception e) {
    LOGGER.error(e.getMessage());
  }
  return false;
}

代码示例来源:origin: zhoulychn/mybatis-generator

/**
 * 拷贝源目录的内容到目的目录中(注:是拷贝到目的目录的里面)
 *
 * @param srcDir
 *            源目录
 * @param destDir
 *            目的目录
 * @return true:拷贝成功 false:拷贝失败
 */
public static boolean copyDirectoryToDirectory(File srcDir, File destDir) {
  try {
    org.apache.commons.io.FileUtils.copyDirectoryToDirectory(srcDir, destDir);
    return true;
  } catch (IOException ex) {
    logger.error("复制目录出错", ex);
  }
  return false;
}

代码示例来源:origin: net.jangaroo/jangaroo-maven-plugin

public static void copyDirectory(@Nonnull File srcDir, @Nonnull File targetDir) throws MojoExecutionException {
 if (srcDir.exists()) {
  try {
   org.apache.commons.io.FileUtils.copyDirectoryToDirectory(srcDir, targetDir);
  } catch (IOException e) {
   throw new MojoExecutionException(String.format("Copying sencha sources from %s to %s failed.", srcDir, targetDir ), e);
  }
 }
}

代码示例来源:origin: raydac/mvn-golang

private void safeCopyDirectory(@Nullable final String src, @Nonnull final File dst) throws IOException {
  if (src == null || src.isEmpty()) {
    return;
  }
  final File srcFile = new File(src);
  if (srcFile.isDirectory()) {
    if (getLog().isDebugEnabled()) {
      getLog().debug(String.format("Copying %s => %s", srcFile.getAbsolutePath(), dst.getAbsolutePath()));
    }
    FileUtils.copyDirectoryToDirectory(srcFile, dst);
  }
}

代码示例来源:origin: org.kuali.ole/ole-workflow-utility

private void copyFileToDestDir(File inputFile) throws IOException {
//        InputStream fileInputStream = new FileInputStream(inputFile);
//        File tempFile = new File(getTempDir(), inputFile.getName());
//        IOUtils.copy(fileInputStream, new FileOutputStream(tempFile));
//        FileUtils.copyFileToDirectory(tempFile, getDestDir());

    if (inputFile.isDirectory()) {
      FileUtils.copyDirectoryToDirectory(inputFile, getDestDir());
    } else if (inputFile.isFile() && FilenameUtils.getExtension(inputFile.getName()).contains("xml")) {
      FileUtils.copyFileToDirectory(inputFile, getDestDir());
    }
  }

代码示例来源:origin: org.n52.wps/52n-wps-ags

public AlgorithmPackage createChild (File destinationRoot) throws IOException{
  FileUtils.copyDirectoryToDirectory(algorithmWorkspace, destinationRoot);
  File wsDir = new File(destinationRoot.getAbsolutePath() + File.separator + getWorkspacePathFragment());
  AlgorithmPackage child = new AlgorithmPackage(processDescription, algorithmDescription, wsDir);
  return child;
}

代码示例来源:origin: org.ow2.petals/jbi-adapter-impl

private void copyAllJbiDirContentExceptJbiXmlFile(File jbiDir) throws IOException {
  for (File fileInJbiDir : jbiDir.listFiles()) {
    if ("jbi.xml".equals(fileInJbiDir.getName())) {
      // jbi.xml was generated just before, skip it.
      continue;
    }
    if (fileInJbiDir.isDirectory()) {
      FileUtils.copyDirectoryToDirectory(fileInJbiDir, getInstallRoot());
    } else {
      FileUtils.copyFileToDirectory(fileInJbiDir, getInstallRoot());
    }
  }
}

代码示例来源:origin: org.xworker/xworker_core

public static void copyDirectoryToDirectory(ActionContext actionContext) throws IOException{
  Thing self = actionContext.getObject("self");
  File srcDir = getFile(self, "getSrcDir", actionContext);
  File destDir = getFile(self, "getDestDir", actionContext);
  
  FileUtils.copyDirectoryToDirectory(srcDir, destDir);
}

相关文章

FileUtils类方法