Java BufferedInputStream Copy copyFile(File source, File target)

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

Description

copy File

License

Open Source License

Declaration

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

Method Source Code


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

public class Main {
    public static void copyFile(File source, File target) throws IOException {
        InputStream in = null;// w w  w  .j  av a2  s.  c o  m
        OutputStream out = null;
        try {
            in = new BufferedInputStream(new FileInputStream(source));
            out = new BufferedOutputStream(new FileOutputStream(target));
            int ch;
            while ((ch = in.read()) != -1) {
                out.write(ch);
            }
            out.flush(); // just in case
        } finally {
            if (out != null)
                try {
                    out.close();
                } catch (IOException ioe) {
                }
            if (in != null)
                try {
                    in.close();
                } catch (IOException ioe) {
                }
        }
    }
}

Related

  1. copyFile(File source, File dest, boolean deleteIfExists)
  2. copyFile(File source, File dest, boolean deleteIfExists)
  3. copyFile(File source, File destination)
  4. copyFile(File source, File destination)
  5. copyFile(File source, File destination, boolean overwrite)
  6. copyFile(File source, File target)
  7. copyFile(File source, File target)
  8. copyFile(File sourceFile, File targetFile)
  9. copyFile(File sourceFile, File targetFile)