Example usage for org.apache.commons.io FileUtils copyFile

List of usage examples for org.apache.commons.io FileUtils copyFile

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils copyFile.

Prototype

public static void copyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException 

Source Link

Document

Copies a file to a new location.

Usage

From source file:edu.monash.merc.util.file.DMFileUtils.java

public static void copyFile(String srcFileName, String destFileName, boolean preserveFileDate) {

    if (srcFileName == null) {
        throw new DMFileException("Source must not be null");
    }//from   ww  w  . j a va 2s. c o  m
    if (destFileName == null) {
        throw new DMFileException("Destination must not be null");
    }
    File srcFile = new File(srcFileName);
    File destFile = new File(destFileName);

    if (!srcFile.exists()) {
        throw new DMFileException("Source '" + srcFile + "' does not exist");
    }
    if (srcFile.isDirectory()) {
        throw new DMFileException("Source '" + srcFile + "' is a directory");
    }

    if (destFile.isDirectory()) {
        throw new DMFileException("Destination '" + destFile + "' is a directory");
    }
    try {
        FileUtils.copyFile(srcFile, destFile, preserveFileDate);
    } catch (Exception e) {
        throw new DMFileException(e);
    }
}

From source file:de.uni_hildesheim.sse.easy.ant.modelcopy.ModelCopy.java

/**
 * Starts the copy process.//from w  w  w .j ava 2s .com
 * @throws ModelManagementException If IVML files could not be parsed
 * @throws IOException If files could not be copied.
 */
private void copy() throws ModelManagementException, IOException {
    // Initialize
    loadProject(getSourceFolder(), getMainProject());
    Collection<File> originalFiles = FileUtils.listFiles(getSourceFolder(), new EASyModelFilter(),
            TrueFileFilter.INSTANCE);

    // Copy all files
    for (File file : originalFiles) {
        String relativeFileName = getSourceFolder().toURI().relativize(file.toURI()).getPath();
        debugMessage("Processing: " + relativeFileName);
        File copyDestination = new File(getDestinationFolder(), relativeFileName);
        if (!copyDestination.exists()) {
            File destFolder = copyDestination.getParentFile();
            destFolder.mkdirs();
            if (!relativeFileName.toLowerCase().endsWith(CONFIG_FILE_EXTENSION)) {
                FileUtils.copyFile(file, copyDestination, false);
            } else {
                handleConfigFile(relativeFileName, destFolder);
            }
        }
    }
}