Java File Copy fileCopy(String from, String to)

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

Description

file copy

License

Apache License

Parameter

Parameter Description
from - from file
to - to file

Declaration

public static void fileCopy(String from, String to) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /**//from  www  . j a v  a  2 s .  c o m
     * <p>
     * file copy
     * <p/>
     * 
     * @param from
     *            - from file
     * @param to
     *            - to file
     * 
     */
    public static void fileCopy(String from, String to) throws IOException {
        FileInputStream fis = null;
        FileOutputStream fos = null;

        try {
            fis = new FileInputStream(from);
            fos = new FileOutputStream(to);

            final int BUFSIZ = 1024;
            byte buf[] = new byte[BUFSIZ];
            int len = 0;

            while ((len = fis.read(buf)) > 0)
                fos.write(buf, 0, len);
        } catch (Exception e) {
            // log.error("FileUtil, fileCopy, Exception error.", e);
        } finally {
            if (fis != null)
                fis.close();
            if (fos != null)
                fos.close();
        }
    }
}

Related

  1. doCopyFile(File srcFile, File destFile, boolean preserveFileDate)
  2. fileCopy(File source, String dest)
  3. fileCopy(File srcFile, File tarFile)
  4. FileCopy(InputStream input, OutputStream output, int bufferSize)
  5. fileCopy(String from, String to)
  6. fileCopy(String fromPath, String toPath)
  7. fileCopy(String oldFilePath, String newFilePath, boolean isCover)
  8. fileCopy(String sFrom, String sTo)
  9. fileCopy(String source, String target)