Java Copy File copyFilesToLocal(String destination, String source)

Here you can find the source of copyFilesToLocal(String destination, String source)

Description

copy Files To Local

License

BSD License

Declaration

protected static String copyFilesToLocal(String destination, String source) 

Method Source Code

//package com.java2s;
/*L/*from   w w  w.  ja  v  a  2  s .  c  o m*/
 * Copyright The General Hospital Corporation d/b/a Massachusetts General Hospital
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/digital-model-repository/LICENSE.txt for details.
 */

import java.io.File;
import java.io.FileInputStream;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    protected static String copyFilesToLocal(String destination, String source) {
        try {
            File f1 = new File(source);
            File f2 = new File(destination, f1.getName());

            InputStream in = new FileInputStream(f1);

            // For Overwrite the file.
            OutputStream out = new FileOutputStream(f2);

            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
            return f2.getName();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. copyFileSafe(File in, File out)
  2. copyFilesBinary(String srcFile, String destDir)
  3. copyFilesBinaryRecursively(File fromLocation, File toLocation, FileFilter fileFilter)
  4. copyFilesFromDirToDir(String originalDir, String targetDir)
  5. copyFilesRecursive(File src, File dest)