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

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

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

FileUtils.moveFileToDirectory介绍

[英]Moves a file to a directory.
[中]将文件移动到目录。

代码示例

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

moveDirectoryToDirectory(src, destDir, createDestDir);
} else {
  moveFileToDirectory(src, destDir, createDestDir);

代码示例来源:origin: SonarSource/sonarqube

public void cancelUninstalls(File uninstallDir) {
 for (File file : listJarFiles(uninstallDir)) {
  try {
   moveFileToDirectory(file, fs.getInstalledPluginsDir(), false);
  } catch (IOException e) {
   throw new IllegalStateException("Fail to cancel plugin uninstalls", e);
  }
 }
}

代码示例来源:origin: Netflix/Priam

protected void moveForgottenFiles(File columnfamilyDir, Collection<File> columnfamilyFiles) {
    final Path destDir = Paths.get(columnfamilyDir.getAbsolutePath(), LOST_FOUND);
    for (File file : columnfamilyFiles) {
      logger.warn(
          "Forgotten file: {} found for CF: {}",
          file.getAbsolutePath(),
          columnfamilyDir.getName());
      if (config.isForgottenFileMoveEnabled()) {
        try {
          FileUtils.moveFileToDirectory(file, destDir.toFile(), true);
        } catch (IOException e) {
          logger.error(
              "Exception occurred while trying to move forgottenFile: {}. Ignoring the error and continuing with remaining backup/forgotten files.",
              file);
          e.printStackTrace();
        }
      }
    }
  }
}

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

FileUtils.moveDirectoryToDirectory(file, tempZipDir, false);
} else {
  FileUtils.moveFileToDirectory(file, tempZipDir, false);

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

@Test
public void testMoveFileToDirectory() throws Exception {
  final File destDir = new File(getTestDirectory(), "moveFileDestDir");
  final File movedFile = new File(destDir, testFile1.getName());
  assertFalse("Check Exist before", destDir.exists());
  assertFalse("Check Exist before", movedFile.exists());
  FileUtils.moveFileToDirectory(testFile1, destDir, true);
  assertTrue("Check Exist after", movedFile.exists());
  assertTrue("Original deleted", !testFile1.exists());
}

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

@Test
public void testMoveFileToDirectory_Errors() throws Exception {
  try {
    FileUtils.moveFileToDirectory(null, new File("foo"), true);
    fail("Expected NullPointerException when source is null");
  } catch (final NullPointerException e) {
    FileUtils.moveFileToDirectory(new File("foo"), null, true);
    fail("Expected NullPointerException when destination is null");
  } catch (final NullPointerException e) {
    FileUtils.moveFileToDirectory(testFile1, testFile2, true);
    fail("Expected IOException when dest not a directory");
  } catch (final IOException e) {
    FileUtils.moveFileToDirectory(testFile1, nonexistant, false);
    fail("Expected IOException when dest does not exist and create=false");
  } catch (final IOException e) {

代码示例来源:origin: SonarSource/sonarqube

/**
 * Uninstall a plugin and its dependents
 */
public void uninstall(String pluginKey, File uninstallDir) {
 Set<String> uninstallKeys = new HashSet<>();
 uninstallKeys.add(pluginKey);
 appendDependentPluginKeys(pluginKey, uninstallKeys);
 for (String uninstallKey : uninstallKeys) {
  PluginInfo info = getPluginInfo(uninstallKey);
  try {
   if (!getPluginFile(info).exists()) {
    LOG.info("Plugin already uninstalled: {} [{}]", info.getName(), info.getKey());
    continue;
   }
   LOG.info("Uninstalling plugin {} [{}]", info.getName(), info.getKey());
   File masterFile = getPluginFile(info);
   moveFileToDirectory(masterFile, uninstallDir, true);
  } catch (IOException e) {
   throw new IllegalStateException(format("Fail to uninstall plugin %s [%s]", info.getName(), info.getKey()), e);
  }
 }
}

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

@Test
public void shouldNotLoadClassesFoundInMETA_INFEvenIfTheyAreProperGoExtensionPoints() throws Exception {
  File bundleWithActivator = createBundleWithActivator(BUNDLE_DIR_WHICH_HAS_PROPER_ACTIVATOR, DummyTestPlugin.class);
  File sourceClassFile = new File(bundleWithActivator, "com/thoughtworks/go/plugin/activation/test/DummyTestPlugin.class");
  File destinationFile = new File(bundleWithActivator, "META-INF/com/thoughtworks/go/plugin/activation/test/");
  FileUtils.moveFileToDirectory(sourceClassFile, destinationFile, true);
  Bundle bundle = installBundleFoundInDirectory(bundleWithActivator);
  assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
  GoPluginDescriptor descriptor = registry.getPlugin(GO_TEST_DUMMY_SYMBOLIC_NAME);
  assertThat(descriptor.isInvalid(), is(true));
  assertThat(descriptor.getStatus().getMessages().contains(NO_EXT_ERR_MSG),is(true));
}

代码示例来源:origin: bonigarcia/webdrivermanager

private Optional<File> downloadAndExtract(URL url, File targetFile)
    throws IOException, InterruptedException {
  log.info("Downloading {}", url);
  File targetFolder = targetFile.getParentFile();
  File tempDir = createTempDirectory("").toFile();
  File temporaryFile = new File(tempDir, targetFile.getName());
  log.trace("Target folder {} ... using temporal file {}", targetFolder,
      temporaryFile);
  copyInputStreamToFile(httpClient.execute(httpClient.createHttpGet(url))
      .getEntity().getContent(), temporaryFile);
  File extractedFile = extract(temporaryFile);
  File resultingBinary = new File(targetFolder, extractedFile.getName());
  boolean binaryExists = resultingBinary.exists();
  if (!binaryExists || config.isOverride()) {
    if (binaryExists) {
      log.info("Overriding former binary {}", resultingBinary);
      deleteFile(resultingBinary);
    }
    moveFileToDirectory(extractedFile, targetFolder, true);
  }
  if (!config.isExecutable(resultingBinary)) {
    setFileExecutable(resultingBinary);
  }
  deleteFolder(tempDir);
  log.trace("Binary driver after extraction {}", resultingBinary);
  return of(resultingBinary);
}

代码示例来源:origin: hortonworks/streamline

private void moveFileToDirectory (File fileToMove, File moveToDirectory) throws IOException {
    FileUtils.moveFileToDirectory(fileToMove, moveToDirectory, false);
  }
}

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

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

代码示例来源:origin: 3zamn/kingMicro

public static void moveFile(File resFile, String distFolder) throws IOException {
  if (resFile != null) {
    File distFile = new File(distFolder);
    if (resFile.isDirectory()) {
      FileUtils.moveDirectoryToDirectory(resFile, distFile, true);
    } else if (resFile.isFile()) {
      FileUtils.moveFileToDirectory(resFile, distFile, true);
    }
  } else {
    throw new IOException("resFile is null and distFolder: " + distFolder);
  }
}

代码示例来源:origin: awslabs/mxnet-model-server

private static void moveToTopLevel(File from, File to) throws IOException {
  File[] list = from.listFiles();
  if (list != null) {
    for (File file : list) {
      if (file.isDirectory()) {
        FileUtils.moveDirectoryToDirectory(file, to, false);
      } else {
        FileUtils.moveFileToDirectory(file, to, false);
      }
    }
  }
}

代码示例来源:origin: 3zamn/kingMicro

public static synchronized void moveFileForce(File resFile,String distFolder) throws IOException{
  File distFile = new File(distFolder);
  if (resFile.isDirectory()) {
    FileUtils.moveDirectoryToDirectory(resFile, distFile, true);
  } else if (resFile.isFile()) {
    File destFile = new File(distFolder, resFile.getName());
    if (destFile.exists()){
      destFile.delete();
    }
    FileUtils.moveFileToDirectory(resFile, distFile, true);
  }
}
/**

代码示例来源:origin: org.mule/mule-core

private void moveToCorruptedFilesFolder(File file) throws IOException
{
  String workingDirectory = (new File(muleContext.getConfiguration().getWorkingDirectory()))
      .toPath().normalize().toString();
  String diffFolder = file.getAbsolutePath().split(workingDirectory)[1];
  File corruptedFile = new File(muleContext.getConfiguration().getWorkingDirectory()
                 + File.separator + CORRUPTED_FOLDER + diffFolder);
  moveFileToDirectory(file, corruptedFile.getParentFile(), true);
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-server

public void cancelUninstalls(File uninstallDir) {
 for (File file : listJarFiles(uninstallDir)) {
  try {
   moveFileToDirectory(file, fs.getInstalledPluginsDir(), false);
  } catch (IOException e) {
   throw new IllegalStateException("Fail to cancel plugin uninstalls", e);
  }
 }
}

代码示例来源:origin: apache/apex-malhar

private void writeErrorFile(int cnt, File errorFile) throws IOException
{
 List<String> allLines = Lists.newArrayList();
 HashSet<String> lines = Sets.newHashSet();
 for (int line = 0; line < 5; line++) {
  lines.add("f0" + "l" + line);
 }
 allLines.addAll(lines);
 FileUtils.write(errorFile, StringUtils.join(lines, '\n'));
 FileUtils.moveFileToDirectory(new File(errorFile.getAbsolutePath()), new File(testMeta.dir), true);
}

代码示例来源:origin: apache/apex-malhar

private void writeAvroFile(File outputFile)
{
 DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<>(new Schema.Parser().parse(AVRO_SCHEMA));
 try (DataFileWriter<GenericRecord> dataFileWriter = new DataFileWriter<>(datumWriter)) {
  dataFileWriter.create(new Schema.Parser().parse(AVRO_SCHEMA), outputFile);
  for (GenericRecord record : recordList) {
   dataFileWriter.append(record);
  }
  FileUtils.moveFileToDirectory(new File(outputFile.getAbsolutePath()), new File(testMeta.dir), true);
 } catch (IOException e) {
  e.printStackTrace();
 }
}

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

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

代码示例来源:origin: apache/apex-malhar

private void writeAvroFile(File outputFile) throws IOException
{
 DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<GenericRecord>(
   new Schema.Parser().parse(AVRO_SCHEMA));
 DataFileWriter<GenericRecord> dataFileWriter = new DataFileWriter<GenericRecord>(datumWriter);
 dataFileWriter.create(new Schema.Parser().parse(AVRO_SCHEMA), outputFile);
 for (GenericRecord record : recordList) {
  dataFileWriter.append(record);
 }
 dataFileWriter.close();
 FileUtils.moveFileToDirectory(new File(outputFile.getAbsolutePath()), new File(testMeta.dir), true);
}

相关文章

FileUtils类方法