Java Utililty Methods Copy File

List of utility methods to do Copy File

Description

The list of methods to do Copy File are organized into topic(s).

Method

voidcopyFilesBinaryRecursively(File fromLocation, File toLocation, FileFilter fileFilter)
Recursively copies files and subdirectories from fromLocation to toLocation using FileFilter fileFliter
if (fromLocation.exists()) {
    for (File fileToCopy : fromLocation.listFiles(fileFilter)) {
        if (fileToCopy.isDirectory()) {
            File newToDir = new File(toLocation, fileToCopy.getName());
            newToDir.mkdir();
            copyFilesBinaryRecursively(fileToCopy, newToDir, fileFilter);
        } else {
            copyFilesBinary(fileToCopy, toLocation);
...
voidcopyFilesFromDirToDir(String originalDir, String targetDir)
copy Files From Dir To Dir
if (!originalDir.endsWith("/")) {
    originalDir = originalDir + "/";
File originalFile = new File(originalDir);
if (!originalFile.exists()) {
    System.out.println(originalFile.getAbsolutePath() + " does not exist.");
    return;
if (!targetDir.endsWith("/")) {
    targetDir = targetDir + "/";
File targetFile = new File(targetDir);
if (!targetFile.exists()) {
    targetFile.mkdirs();
String[] files = null;
files = originalFile.list();
for (String filename : files) {
    if (!filename.endsWith(".png"))
        continue;
    InputStream in = null;
    OutputStream out = null;
    try {
        in = new FileInputStream(originalDir + filename);
        out = new FileOutputStream(targetDir + filename);
        copyFile(in, out);
        in.close();
        in = null;
        out.flush();
        out.close();
        out = null;
    } catch (Exception e) {
        System.out.println(e.getMessage());
ListcopyFilesRecursive(File src, File dest)
Copies files and directories recursively.
ArrayList<File> list = new ArrayList<File>();
if (!src.exists()) {
    throw new FileNotFoundException("Input file does not exist.");
if (src.isDirectory()) {
    if (!dest.exists()) {
        dest.mkdirs();
    } else if (!dest.isDirectory()) {
...
StringcopyFilesToLocal(String destination, String source)
copy Files To Local
try {
    File f1 = new File(source);
    File f2 = new File(destination, f1.getName());
    InputStream in = new FileInputStream(f1);
    OutputStream out = new FileOutputStream(f2);
    byte[] buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) > 0) {
...