Java FileInputStream Copy copyFile(String src, String dest)

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

Description

Copies a file.

License

Open Source License

Parameter

Parameter Description
src The path of the source file
dest The location to copy the file to.

Exception

Parameter Description
FileNotFoundException If the source file could not be found
IOException If we encountered some sort of read/write error

Declaration


public static void copyFile(String src, String dest) throws FileNotFoundException, IOException 

Method Source Code

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

import java.io.File;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import java.io.IOException;

public class Main {
    /**//w  w  w .  ja  v  a2s.com
     * Copies a file.
     * 
     * @param src The path of the source file
     * @param dest The location to copy the file to.
     * 
     * @throws FileNotFoundException If the source file could not be found
     * @throws IOException If we encountered some sort of read/write error
     */

    public static void copyFile(String src, String dest) throws FileNotFoundException, IOException {
        FileInputStream in = new FileInputStream(new File(src));
        FileOutputStream out = new FileOutputStream(new File(dest));

        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0)
            out.write(buf, 0, len);

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

Related

  1. copyFile(String sourcePath, String newPath)
  2. copyFile(String src, File dest)
  3. copyFile(String src, String dest)
  4. copyFile(String src, String dest)
  5. copyFile(String src, String dest)
  6. copyFile(String src, String dest)
  7. copyFile(String src, String dst)
  8. copyFile(String src, String dst)
  9. copyFile(String src, String tar)