Java Code Examples for org.apache.commons.io.FileUtils.moveFileToDirectory()

The following are Jave code examples for showing how to use moveFileToDirectory() of the org.apache.commons.io.FileUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Reer   File: TestFile.java   View Source Code Vote up 5 votes
public void moveToDirectory(File target) {
    if (target.exists() && !target.isDirectory()) {
        throw new RuntimeException(String.format("Target '%s' is not a directory", target));
    }
    try {
        FileUtils.moveFileToDirectory(this, target, true);
    } catch (IOException e) {
        throw new RuntimeException(String.format("Could not move test file '%s' to directory '%s'", this, target), e);
    }
}
 
Example 2
Project: dhus-core   File: FileSystemDataStore.java   View Source Code Vote up 5 votes
/**
 * Moves product download zip into the given destination.
 * <p><b>Note:</b> generates the zip of product if necessary.</p>
 *
 * @param product     product to move.
 * @param destination destination of product
 */
private void moveProduct (Product product, String destination)
{

   if (destination == null || destination.trim ().isEmpty ())
   {
      return;
   }

   Path zip_destination = Paths.get (destination);
   String download_path = product.getDownloadablePath ();
   try
   {
      if (download_path != null)
      {
         File product_zip_file = Paths.get (download_path).toFile ();
         FileUtils.moveFileToDirectory (
               product_zip_file, zip_destination.toFile (), true);
      }
      else
      {
         Path product_path = Paths.get (product.getPath ().getPath ());
         if (UnZip.supported (product_path.toAbsolutePath ().toString ()))
         {
            FileUtils.moveFileToDirectory (
                  product_path.toFile (), zip_destination.toFile (), true);
         }
         else
         {
            zip_destination.resolve (product_path.getFileName ());
            generateZip (product_path.toFile (), zip_destination.toFile ());
         }
      }
   }
   catch (IOException e)
   {
      LOGGER.error("Cannot move product: " + product.getPath () +
            " into " + destination, e);
   }
}
 
Example 3
Project: aliyun-maxcompute-data-collectors   File: DataDrivenImportJob.java   View Source Code Vote up 5 votes
private void writeAvroSchema(final Schema schema) throws IOException {
  // Generate schema in JAR output directory.
  final File schemaFile = new File(options.getJarOutputDir(), schema.getName() + ".avsc");

  LOG.info("Writing Avro schema file: " + schemaFile);
  FileUtils.forceMkdir(schemaFile.getParentFile());
  FileUtils.writeStringToFile(schemaFile, schema.toString(true));

  // Copy schema to code output directory.
  try {
    FileUtils.moveFileToDirectory(schemaFile, new File(options.getCodeOutputDir()), true);
  } catch (final IOException e) {
    LOG.debug("Could not move Avro schema file to code output directory.", e);
  }
}
 
Example 4
Project: phonk   File: PFileIO.java   View Source Code Vote up 5 votes
@ProtoMethod(description = "Move a file to a directory", example = "")
@ProtoMethodParam(params = {"name", "destination"})
public void move(String name, String to) {
    File fromFile = new File(getAppRunner().getProject().getFullPathForFile(name));
    File dir = new File(getAppRunner().getProject().getFullPathForFile(to));

    dir.mkdirs();
    try {
        FileUtils.moveFileToDirectory(fromFile, dir, false);
    } catch (IOException e) {
        e.printStackTrace();
    }
}