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

Declaration

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

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    public static void copyFile(File source, File dest) throws IOException {
        if (!dest.exists()) {
            dest.createNewFile();/*from w w w  .  j  a v a2  s  . c o  m*/
        }
        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(source);
            out = new FileOutputStream(dest);

            // Transfer bytes from in to out
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
    }
}

Related

  1. copyFile(File original, File parent)
  2. copyFile(File originalFile, File destinationDir)
  3. copyFile(File pSrc, File pDst, boolean pForce)
  4. copyFile(File source, File dest)
  5. copyFile(File source, File dest)
  6. copyFile(File source, File dest)
  7. copyFile(File source, File dest)
  8. copyFile(File source, File dest)
  9. copyFile(File source, File dest)