Java FileInputStream Copy copyFile(File source, File dest)

Here you can find the source of copyFile(File source, File dest)

Description

copy File

License

Open Source License

Parameter

Parameter Description
source File to be copied
dest File where to put the copy of source

Exception

Parameter Description

Declaration

public static void copyFile(File source, File dest) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    /**//  www.jav  a  2 s. c om
     * 
     * @param source File to be copied
     * @param dest File where to put the copy of source
     * @throws java.io.IOException
     */
    public static void copyFile(File source, File dest) throws IOException {
        if (!dest.exists()) {
            dest.createNewFile();
        }
        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(source);
            out = new FileOutputStream(dest);
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }

        } finally {
            in.close();
            out.close();
        }
    }
}

Related

  1. copyFile(File source, File dest)
  2. copyFile(File source, File dest)
  3. copyFile(File source, File dest)
  4. copyFile(File source, File dest)
  5. copyFile(File source, File dest)
  6. copyFile(File source, File dest)
  7. copyFile(File source, File destination)
  8. copyFile(File source, File destination)
  9. copyFile(File source, File destination)