本文整理了Java中org.apache.commons.io.FileUtils.copyDirectory()
方法的一些代码示例,展示了FileUtils.copyDirectory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.copyDirectory()
方法的具体详情如下:
包路径:org.apache.commons.io.FileUtils
类名称:FileUtils
方法名:copyDirectory
[英]Copies a whole directory to a new location preserving the file dates.
This method copies the specified directory and all its child directories and files to the specified destination. The destination is the new location and name of the 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: commons-io/commons-io
throw new IllegalArgumentException("Destination '" + destDir + "' is not a directory");
copyDirectory(srcDir, new File(destDir, srcDir.getName()), true);
代码示例来源:origin: ming1016/study
public static void copyResourcesRecursively(URL originUrl, File destination) throws Exception {
URLConnection urlConnection = originUrl.openConnection();
if (urlConnection instanceof JarURLConnection) {
copyJarResourcesRecursively(destination, (JarURLConnection) urlConnection);
} else if (urlConnection instanceof FileURLConnection) {
FileUtils.copyDirectory(new File(originUrl.getPath()), destination);
} else {
die("Unsupported URL type: " + urlConnection);
}
}
代码示例来源:origin: ming1016/study
public static void copyResourcesRecursively(URL originUrl, File destination) throws Exception {
URLConnection urlConnection = originUrl.openConnection();
if (urlConnection instanceof JarURLConnection) {
copyJarResourcesRecursively(destination, (JarURLConnection) urlConnection);
} else if (urlConnection instanceof FileURLConnection) {
FileUtils.copyDirectory(new File(originUrl.getPath()), destination);
} else {
die("Unsupported URL type: " + urlConnection);
}
}
代码示例来源: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: apache/kylin
@Override
public void hook() throws IOException {
//some test cases may require additional metadata entries besides standard test metadata in test_case_data/localmeta
for (String overlay : overlayMetadataDirs) {
FileUtils.copyDirectory(new File(overlay), new File(LOCALMETA_TEMP_DATA));
}
}
}
代码示例来源:origin: apache/incubator-pinot
/**
* NOTE: original segment should be in V1 format.
* TODO: support V3 format
*/
public RawIndexConverter(@Nonnull File originalIndexDir, @Nonnull File convertedIndexDir,
@Nullable String columnsToConvert)
throws Exception {
FileUtils.copyDirectory(originalIndexDir, convertedIndexDir);
IndexLoadingConfig indexLoadingConfig = new IndexLoadingConfig();
indexLoadingConfig.setSegmentVersion(SegmentVersion.v1);
indexLoadingConfig.setReadMode(ReadMode.mmap);
_originalImmutableSegment = ImmutableSegmentLoader.load(originalIndexDir, indexLoadingConfig);
_originalSegmentMetadata = (SegmentMetadataImpl) _originalImmutableSegment.getSegmentMetadata();
_convertedIndexDir = convertedIndexDir;
_convertedProperties =
new PropertiesConfiguration(new File(_convertedIndexDir, V1Constants.MetadataKeys.METADATA_FILE_NAME));
_columnsToConvert = columnsToConvert;
}
代码示例来源:origin: apache/zookeeper
@Before
public void setUp() throws IOException {
System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
File snapDir = new File(testData, "invalidsnap");
mySnapDir = ClientBase.createTmpDir();
FileUtils.copyDirectory(snapDir, mySnapDir);
}
代码示例来源:origin: twosigma/beakerx
private static void prepareLocalMavenRepository() throws IOException {
FileUtils.copyDirectory(new File(SRC_TEST_RESOURCES_TEST_MVN_CACHE), new File(BUILD_PATH));
unzipRepo();
}
代码示例来源:origin: twosigma/beakerx
private static void prepareLocalMavenRepository() throws IOException {
FileUtils.copyDirectory(new File(SRC_TEST_RESOURCES_TEST_MVN_CACHE), new File(BUILD_PATH));
unzipRepo();
}
代码示例来源:origin: apache/hive
@Override
public void beforeClass(HiveTestEnvContext ctx) throws Exception {
File confFolder = new File(ctx.tmpFolder, "conf");
FileUtils.copyDirectory(new File(DATA_DIR + "/conf/"), confFolder);
FileUtils.copyDirectory(new File(DATA_DIR + "/conf/tez"), confFolder);
HiveConf.setHiveSiteLocation(new File(confFolder, "hive-site.xml").toURI().toURL());
HiveConf.setHivemetastoreSiteUrl(new File(confFolder, "hivemetastore-site.xml").toURI().toURL());
// FIXME: hiveServer2SiteUrl is not settable?
ctx.hiveConf = new HiveConf(IDriver.class);
ctx.hiveConf.setBoolVar(ConfVars.HIVE_IN_TEST_IDE, true);
}
代码示例来源:origin: gocd/gocd
public SvnTestRepo(TemporaryFolder temporaryFolder, String folderName) throws IOException {
super(temporaryFolder);
if (isBlank(folderName)) {
tempRepo = temporaryFolder.newFolder();
} else {
tempRepo = temporaryFolder.newFolder(folderName);
}
tmpFolders.add(tempRepo);
try {
copyDirectory(new File(REPO_TEST_DATA_FOLDER), tempRepo);
} catch (IOException e) {
Assert.fail("Could not copy test repo [" + REPO_TEST_DATA_FOLDER + "] into [" + tempRepo + "] beacuse of " + e.getMessage());
}
new File(tempRepo, "/project1/db/transactions").mkdir();
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testCopyDirectoryFiltered() throws Exception {
final File grandParentDir = new File(getTestDirectory(), "grandparent");
final File parentDir = new File(grandParentDir, "parent");
final File childDir = new File(parentDir, "child");
createFilesForTestCopyDirectory(grandParentDir, parentDir, childDir);
final NameFileFilter filter = new NameFileFilter(new String[]{"parent", "child", "file3.txt"});
final File destDir = new File(getTestDirectory(), "copydest");
FileUtils.copyDirectory(grandParentDir, destDir, filter);
final List<File> files = LIST_WALKER.list(destDir);
assertEquals(3, files.size());
assertEquals("parent", files.get(0).getName());
assertEquals("child", files.get(1).getName());
assertEquals("file3.txt", files.get(2).getName());
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testCopyDirectoryErrors() throws Exception {
try {
FileUtils.copyDirectory(null, null);
fail();
} catch (final NullPointerException ignore) {
FileUtils.copyDirectory(new File("a"), null);
fail();
} catch (final NullPointerException ignore) {
FileUtils.copyDirectory(null, new File("a"));
fail();
} catch (final NullPointerException ignore) {
FileUtils.copyDirectory(new File("doesnt-exist"), new File("a"));
fail();
} catch (final IOException ignore) {
FileUtils.copyDirectory(testFile1, new File("a"));
fail();
} catch (final IOException ignore) {
FileUtils.copyDirectory(getTestDirectory(), testFile1);
fail();
} catch (final IOException ignore) {
FileUtils.copyDirectory(getTestDirectory(), getTestDirectory());
fail();
} catch (final IOException ignore) {
代码示例来源:origin: gocd/gocd
private P4TestRepo(int port, String repoPrototype, String user, String password, String clientName,
boolean useTickets, TemporaryFolder temporaryFolder, File clientFolder) throws IOException {
super(temporaryFolder);
this.port = port;
this.user = user;
this.password = password;
this.clientName = clientName;
this.useTickets = useTickets;
tempRepo = temporaryFolder.newFolder();
this.clientFolder = clientFolder;
try {
copyDirectory(new File(repoPrototype), tempRepo);
} catch (IOException e) {
bomb(e);
}
}
代码示例来源:origin: commons-io/commons-io
final File subDir = new File(srcDir, "sub");
subDir.mkdir();
final File subFile = new File(subDir, "A.txt");
FileUtils.writeStringToFile(subFile, "HELLO WORLD", "UTF8");
final File destDir = new File(System.getProperty("java.io.tmpdir"), "tmp-FileUtilsTestCase");
FileUtils.deleteDirectory(destDir);
destDir.mkdirs();
FileUtils.copyDirectory(srcDir, destDir);
代码示例来源:origin: azkaban/azkaban
@Before
public void setUp() throws Exception {
// TODO: reallocf Remove initServiceProvider when ProcessJob fully guiced
initServiceProvider();
final File jobTypeDir = this.temp.newFolder(TEST_PLUGIN_DIR);
this.testPluginDirPath = jobTypeDir.getCanonicalPath();
final URL resourceUrl = Resources.getResource("plugins/jobtypes");
assertNotNull(resourceUrl);
FileUtils.copyDirectory(new File(resourceUrl.toURI()), jobTypeDir);
this.manager = new JobTypeManager(this.testPluginDirPath, null,
this.getClass().getClassLoader());
}
代码示例来源:origin: commons-io/commons-io
final File subDir = new File(srcDir, "sub");
subDir.mkdir();
final File subFile = new File(subDir, "A.txt");
FileUtils.writeStringToFile(subFile, "HELLO WORLD", "UTF8");
final File destDir = new File(System.getProperty("java.io.tmpdir"), "tmp-FileUtilsTestCase");
FileUtils.deleteDirectory(destDir);
FileUtils.copyDirectory(srcDir, destDir);
代码示例来源:origin: commons-io/commons-io
@Test
public void testCopyDirectoryPreserveDates() throws Exception {
final File source = new File(getTestDirectory(), "source");
final File sourceDirectory = new File(source, "directory");
final File sourceFile = new File(sourceDirectory, "hello.txt");
FileUtils.copyDirectory(source, target, false);
assertTrue(1000000000000L != target.lastModified());
assertTrue(1000000001000L != targetDirectory.lastModified());
FileUtils.copyDirectory(source, target, true);
assertEquals(1000000000000L, target.lastModified());
assertEquals(1000000001000L, targetDirectory.lastModified());
FileUtils.copyDirectory(source, target, true);
assertEquals(1000000000000L, target.lastModified());
assertEquals(1000000001000L, targetDirectory.lastModified());
FileUtils.copyDirectory(source, target, true);
assertEquals(1000000000000L, target.lastModified());
assertEquals(1000000001000L, targetDirectory.lastModified());
代码示例来源:origin: SonarSource/sonarqube
private File copyProject(String path) throws Exception {
File projectDir = temp.newFolder();
File originalProjectDir = new File(path);
FileUtils.copyDirectory(originalProjectDir, projectDir, FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter(".sonar")));
return projectDir;
}
代码示例来源:origin: SonarSource/sonarqube
private File copyProject(String path) throws Exception {
File projectDir = temp.newFolder();
File originalProjectDir = new File(path);
FileUtils.copyDirectory(originalProjectDir, projectDir, FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter(".sonar")));
return projectDir;
}
内容来源于网络,如有侵权,请联系作者删除!