Java File Copy copyFiles(String from, String to)

Here you can find the source of copyFiles(String from, String to)

Description

copy Files

License

Open Source License

Declaration

public static void copyFiles(String from, String to) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2005, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
     //from  w  ww  . j a  v a  2 s .co  m
 *******************************************************************************/

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;

import org.eclipse.dltk.core.DLTKCore;

public class Main {
    public static void copyFiles(String from, String to) {
        File file = new File(from);
        File toFolder = new File(to);
        if (!file.exists() || !file.isDirectory()) {
            return;
        }
        File[] files = file.listFiles();
        for (int i = 0; i < files.length; i++) {
            File child = new File(toFolder, files[i].getName());
            if (files[i].isDirectory()) {
                child.mkdir();
                copyFiles(files[i].getAbsolutePath(), child.getAbsolutePath());
            } else if (files[i].isFile()) {
                BufferedInputStream input;
                try {
                    input = new BufferedInputStream(new FileInputStream(files[i]));
                    org.eclipse.dltk.compiler.util.Util.copy(child, input);
                    input.close();
                } catch (FileNotFoundException e) {
                    if (DLTKCore.DEBUG) {
                        e.printStackTrace();
                    }
                } catch (IOException e) {
                    if (DLTKCore.DEBUG) {
                        e.printStackTrace();
                    }
                }
            }
            child.setLastModified(files[i].lastModified());
        }
    }
}

Related

  1. copyFiles(File src, File dest, FilenameFilter filter)
  2. copyFiles(File src, File dest, String... filenameExtension)
  3. copyFiles(File srcDir, File destDir, String... regexps)
  4. copyFiles(File srcFile, File destFolder)
  5. copyFiles(InputStream inStream, FileOutputStream outStream)
  6. copyFiles(String fromDirName, String toDirName)
  7. copyFileToPath(String fileToPath, String fileName, String sourceFile)
  8. doCopyFile(File srcFile, File destFile, boolean preserveFileDate)
  9. doCopyFile(File srcFile, File destFile, boolean preserveFileDate)