Java Copy File copyFiles(String srcFilePath, String destFilePath)

Here you can find the source of copyFiles(String srcFilePath, String destFilePath)

Description

This method is used for coping file from one place to the other.

License

Open Source License

Parameter

Parameter Description
srcFilePath a parameter
destFilePath a parameter

Exception

Parameter Description
IOException in case some problems occured

Declaration

public static void copyFiles(String srcFilePath, String destFilePath) throws IOException 

Method Source Code

//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

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

public class Main {
    /**//from   ww  w.j  a  v  a  2 s  .c o m
     * 
     */
    private static final int COPY_BUF_SIZE = 512;

    /**
     * This method is used for coping file from one place to the other.
     * 
     * @param srcFilePath
     * @param destFilePath
     * @throws IOException
     * @throws IOException in case some problems occured
     */
    public static void copyFiles(String srcFilePath, String destFilePath) throws IOException {
        FileInputStream input = null;
        FileOutputStream output = null;
        try {
            input = new FileInputStream(srcFilePath);
            output = new FileOutputStream(destFilePath);
            copyStreams(input, output);
        } finally {
            if (input != null) {
                input.close();
            }
            if (output != null) {
                output.close();
            }
        }
    }

    /**
     * copy is to os.
     * 
     * @param is
     * @param os
     * @throws IOException thrown if copy fails
     */
    public static void copyStreams(InputStream is, OutputStream os) throws IOException {
        byte[] bytearray = new byte[COPY_BUF_SIZE];
        int len = 0;
        while ((len = is.read(bytearray)) != -1) {
            os.write(bytearray, 0, len);
        }
    }
}

Related

  1. copyFiles(String p_source, String p_target)
  2. copyFiles(String srcFolderStr, String destFolderStr)
  3. copyFiles(String srcPath, String destPath)
  4. CopyFiles(String strOrgFile, String strDestFile, boolean bFailIfExists)
  5. copyFiles(String strPath, String dstPath, String srcExtension)