Java FileInputStream Copy copyFile(File src, File dst)

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

Description

copy File

License

Open Source License

Declaration

static boolean copyFile(File src, File dst) 

Method Source Code


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

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class Main {
    static boolean copyFile(File src, File dst) {
        byte[] buf = new byte[65536];
        int read;

        try {/*  w  w w.ja va  2  s  . c  o m*/
            FileInputStream fis = new FileInputStream(src);
            FileOutputStream fos = new FileOutputStream(dst);

            while ((read = fis.read(buf)) > 0)
                fos.write(buf, 0, read);

            silentClose(fos);
            silentClose(fis);
            return true;
        } catch (Throwable t) {
            System.err.println(
                    "Could NOT copy \"" + src.getAbsolutePath() + "\" to \"" + dst.getAbsolutePath() + "\":");
            t.printStackTrace();
            return false;
        }
    }

    static void silentClose(Object o) {
        try {
            o.getClass().getMethod("close").invoke(o);
        } catch (Throwable t) {
        }
    }
}

Related

  1. copyFile(File src, File dst)
  2. copyFile(File src, File dst)
  3. copyFile(File src, File dst)
  4. copyFile(File src, File dst)
  5. copyFile(File src, File dst)
  6. copyFile(File src, File dst)
  7. copyFile(File src, File dst)
  8. copyFile(File src, File dst)
  9. copyFile(File src, File dst, boolean copyLMD)