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

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

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

FileUtils.moveToDirectory介绍

[英]Moves a file or directory to the destination directory.

When the destination is on another file system, do a "copy and delete".
[中]将文件或目录移动到目标目录。
当目标位于另一个文件系统上时,请执行“复制并删除”。

代码示例

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

@Test
public void testMoveToDirectory() throws Exception {
  final File destDir = new File(getTestDirectory(), "testMoveToDirectoryDestDir");
  final File testDir = new File(getTestDirectory(), "testMoveToDirectoryTestDir");
  final File testFile = new File(getTestDirectory(), "testMoveToDirectoryTestFile");
  testDir.mkdirs();
  if (!testFile.getParentFile().exists()) {
    throw new IOException("Cannot create file " + testFile
        + " as the parent directory does not exist");
  }
  final BufferedOutputStream output =
      new BufferedOutputStream(new FileOutputStream(testFile));
  try {
    TestUtils.generateTestData(output, 0);
  } finally {
    IOUtils.closeQuietly(output);
  }
  final File movedFile = new File(destDir, testFile.getName());
  final File movedDir = new File(destDir, testFile.getName());
  assertFalse("Check File Doesnt exist", movedFile.exists());
  assertFalse("Check Dir Doesnt exist", movedDir.exists());
  // Test moving a file
  FileUtils.moveToDirectory(testFile, destDir, true);
  assertTrue("Check File exists", movedFile.exists());
  assertFalse("Check Original File doesn't exist", testFile.exists());
  // Test moving a directory
  FileUtils.moveToDirectory(testDir, destDir, true);
  assertTrue("Check Dir exists", movedDir.exists());
  assertFalse("Check Original Dir doesn't exist", testDir.exists());
}

代码示例来源:origin: simpligility/android-maven-plugin

FileUtils.moveToDirectory( new File( libsFolder, nativeLibPath ), jniFolder, true );

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

@Test
public void testMoveToDirectory_Errors() throws Exception {
  try {
    FileUtils.moveDirectoryToDirectory(null, new File("foo"), true);
    fail("Expected NullPointerException when source is null");
  } catch (final NullPointerException e) {
    // expected
  }
  try {
    FileUtils.moveDirectoryToDirectory(new File("foo"), null, true);
    fail("Expected NullPointerException when destination is null");
  } catch (final NullPointerException e) {
    // expected
  }
  final File nonexistant = new File(getTestDirectory(), "nonexistant");
  final File destDir = new File(getTestDirectory(), "MoveToDirectoryDestDir");
  try {
    FileUtils.moveToDirectory(nonexistant, destDir, true);
    fail("Expected IOException when source does not exist");
  } catch (final IOException e) {
    // expected
  }
}

代码示例来源:origin: omero/blitz

void moveToDir(CheckedPath target, boolean createDestDir) throws IOException {
  FileUtils.moveToDirectory(file, target.file, createDestDir);
}

代码示例来源:origin: org.xwiki.platform/xwiki-platform-store-filesystem-oldcore

protected void moveFolderContent(File sourceFolder, File toFolder) throws DataMigrationException
  {
    this.logger.info("Moving content of folder [{}] to new location [{}]", sourceFolder, toFolder);

    for (File child : sourceFolder.listFiles()) {
      try {
        FileUtils.moveToDirectory(child, toFolder, true);
      } catch (IOException e) {
        throw new DataMigrationException(
          "Failed to move content of folder [" + sourceFolder + "] the new location [" + toFolder + "]");
      }
    }
  }
}

代码示例来源:origin: org.apache.openejb/apache-tomee-deb-package

public void createDebPackage(String isControl, String isPostinst, String isPrerm, File md5sums, File data, File deb) throws IOException {
  final File debFolder = new File(deb.getParent(), "DEBIAN");
  debFolder.mkdirs();
  FileUtils.cleanDirectory(debFolder);
  FileUtils.moveToDirectory(data, debFolder, true);
  final File control = new File(debFolder, "control");
  control.mkdirs();
  FileUtils.writeStringToFile(new File(control, "control"), isControl);
  FileUtils.writeStringToFile(new File(control, "postinst"), isPostinst);
  FileUtils.writeStringToFile(new File(control, "prerm"), isPrerm);
  FileUtils.moveToDirectory(md5sums, control, true);
  FileUtils.writeStringToFile(new File(debFolder, "debian-binary"), "2.0\n");
  compressTarGz(control, null, null);
  try {
    ar(debFolder, FilenameUtils.getBaseName(deb.getName()));
  } catch (ArchiveException e) {
    throw new PackageException(e);
  }
  FileUtils.deleteDirectory(debFolder);
}

代码示例来源:origin: com.atlassian.maven.plugins/maven-amps-plugin

/**
 * Overridden as most FeCru ZIPped test data is of a different non-standard structure,
 * i.e. standard structure should have a single root folder.
 * If it finds something looking like the old structure it will re-organize the data to match what is expected
 * of the new structure.
 * @param tmpDir
 * @param ctx
 * @return
 * @throws MojoExecutionException
 * @throws IOException
 */
@Override
protected File getRootDir(File tmpDir, Product ctx) throws MojoExecutionException, IOException
{
  File[] topLevelFiles = tmpDir.listFiles();
  if (topLevelFiles.length != 1)
  {
    log.info("Non-standard zip structure identified. Assume using older non-standard FECRU zip format");
    log.info("Therefore reorganise unpacked data directories to match standard format.");
    File tmpGen = new File(tmpDir, "generated-resources");
    File tmpHome = new File(tmpGen, ctx.getId() + "-home");
    for(File file : topLevelFiles)
    {
      FileUtils.moveToDirectory(file, tmpHome, true);
    }
    return tmpGen;
  }
  return topLevelFiles[0];
}

代码示例来源:origin: com.atlassian.maven.plugins/amps-maven-plugin

/**
 * Overridden as most FeCru ZIPped test data is of a different non-standard structure,
 * i.e. standard structure should have a single root folder.
 * If it finds something looking like the old structure it will re-organize the data to match what is expected
 * of the new structure.
 * @param tmpDir
 * @param ctx
 * @return
 * @throws MojoExecutionException
 * @throws IOException
 */
@Override
protected File getRootDir(File tmpDir, Product ctx) throws MojoExecutionException, IOException
{
  File[] topLevelFiles = tmpDir.listFiles();
  if (topLevelFiles.length != 1)
  {
    log.info("Non-standard zip structure identified. Assume using older non-standard FECRU zip format");
    log.info("Therefore reorganise unpacked data directories to match standard format.");
    File tmpGen = new File(tmpDir, "generated-resources");
    File tmpHome = new File(tmpGen, ctx.getId() + "-home");
    for(File file : topLevelFiles)
    {
      FileUtils.moveToDirectory(file, tmpHome, true);
    }
    return tmpGen;
  }
  return topLevelFiles[0];
}

代码示例来源:origin: ManyDesigns/Portofino

public void markFailed(String id) throws QueueException {
  checkDirectories();
  try {
    File emailFile = getEmailFile(id);
    if(emailFile.exists()) {
      File attachmentsDir = getEmailAttachmentsDirectory(id);
      logger.info("Marking email with id {} as failed", id);
      FileUtils.moveToDirectory(emailFile, failedDirectory, false);
      if(attachmentsDir.exists()) {
        FileUtils.moveToDirectory(attachmentsDir, failedDirectory, false);
      }
    } else {
      logger.debug("Not marking email with id {} as failed", id);
    }
  } catch (IOException e) {
    throw new QueueException("Couldn't mark mail as failed", e);
  }
}

代码示例来源:origin: org.xwiki.platform/xwiki-platform-store-filesystem-oldcore

private void migrateRoot(File newStore) throws DataMigrationException
{
  // Move the whole store folder content to the new location
  File oldStore = getPre11StoreRootDirectory();
  // Check if there is a filesystem store at all
  File[] children = oldStore.listFiles();
  if (ArrayUtils.isEmpty(children)) {
    // Nothing to migrate
    return;
  }
  this.logger.info("Moving content of folder [{}] to new location [{}]", oldStore, newStore);
  for (File child : children) {
    try {
      FileUtils.moveToDirectory(child, newStore, true);
    } catch (IOException e) {
      throw new DataMigrationException("Failed to move old filesystem store to the new location", e);
    }
  }
  // Get rid of old store
  try {
    Files.delete(oldStore.toPath());
  } catch (IOException e) {
    this.logger.warn("Failed to delete old store location [{}]", oldStore);
  }
}

代码示例来源:origin: ManyDesigns/Portofino

if(keepSent) {
  logger.info("Moving email with id {} to sent directory", id);
  FileUtils.moveToDirectory(emailFile, sentDirectory, false);
  if(attachmentsDir.exists()) {
    FileUtils.moveToDirectory(attachmentsDir, sentDirectory, false);

代码示例来源:origin: org.apache.openejb/apache-tomee-deb-package

public File buildDataTarGzFolder(File baseDir, Map<String, String> dirMappings) {
  final File dataTarGzDir = new File(baseDir.getParent(), "data");
  try {
    FileUtils.deleteDirectory(dataTarGzDir);
  } catch (IOException e) {
    throw new PackageException(e);
  }
  final int baseDirLength = baseDir.getAbsolutePath().length();
  final File[] files = baseDir.listFiles();
  for (File entry : files) {
    final String basePath = entry.getAbsolutePath().substring(baseDirLength).replaceAll("\\\\", "/");
    final String dest = dirMappings.get(basePath);
    if (dest == null) {
      throw new PackageException("i don't know where the entry should go. Entry: " + basePath);
    }
    final File destFile = new File(dataTarGzDir, dest);
    try {
      FileUtils.moveToDirectory(entry, destFile, true);
    } catch (IOException e) {
      throw new PackageException(e);
    }
  }
  try {
    FileUtils.deleteDirectory(baseDir);
  } catch (IOException e) {
    throw new PackageException(e);
  }
  return dataTarGzDir;
}

代码示例来源:origin: liimaorg/liima

org.apache.commons.io.FileUtils.moveToDirectory(child, target, true);

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

public static void moveToDirectory(ActionContext actionContext) throws IOException{
  Thing self = actionContext.getObject("self");
  File src = getFile(self, "getSrc", actionContext);
  File destDir = getFile(self, "getDestDir", actionContext);
  Boolean createDestDir = (Boolean) self.doAction("getCreateDestDir", actionContext);
  FileUtils.moveToDirectory(src, destDir, createDestDir);
}

代码示例来源:origin: datasalt/splout-db

binary.delete();
FileUtils.moveToDirectory(binaryToMove, getLocalStorageFolder(tablespace, partition, version), true);
log.info("Balance action successfully completed, received both .db and .meta files (" + tablespace + ", " + partition + ", "
  + version + ")");

相关文章

FileUtils类方法